Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can run a DOS command inside a perl script..Plz help! 1

Status
Not open for further replies.

ejaj

Programmer
Sep 26, 2002
7
0
0
DE
Hi

I am recently facing a strange problem while trying to execute a dos command in my perl script. For example
if I want to copy a file from a soure to a desitnation, it cant find that file. Eg.


$test=`copy C:\project\test\saves\output.txt D:\project\test\`;
print "$test\n";
#c:\project\term\test1.pl#

After executing the script, it gives me the print out at STDOUT as
"The system cannot find the indicated file"

But, when i use the dos command in a command window, the copy command executes.
i even try writing like
system(`copy C:\project\test\saves\output.txt D:\project\test\`);
...

But the msg is same along with some number like 256 is printed on STDOUT.

I dont understand the reason. The file name and paths are also correct.
I will be grateful, if any1 can give me a solution of this weired problem.
Thanks.

Ejaj


 
Hi ejaj,

I realize this does not answer the question as to why the dos copy command is failing when using the backtick technique, but if you are only interested in copying files, perhaps you might try File::Copy. If you are using ActiveState Perl, it should be included.

use File::Copy;
copy("file1","file2");


Hope this helps,
Grant.
 
Have you tried;
$test=`copy C:\\project\\test\\saves\\output.txt D:\\project\\test\\output.txt`;
print "$test\n";
#c:\project\term\test1.pl#

Don't know about DOS, but NT used to chuck weird stuff with Perl
 
It worked!..:) Thank you both PaulTEG & Grant. It was really a nice help.

Ejaj
 
You could also have tried

$test=`copy C:/project/test/saves/output.txt D:/project/test/output.txt`;
print "$test\n";
#c:/project/term/test1.pl#

Just a little easier on the eye...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top