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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

system( "dir") etc... fails... 1

Status
Not open for further replies.

LiquidBinary

Programmer
Jul 27, 2001
148
US
I am running ActivePerl for the win32 platform. A problem arises when I call the system() sub. I cannot execute any commands such as system("dir"),system("cls") etc...The call just returns while printing nothing on the console. These commands work when manually typing them into a dos console, and the system() function call works while calling it from a C program. I just don't understand why it is failing when called from a script. Please help. Mike L.G.
mlg400@blazemail.com
 
Using the system command isn't supposed to display anything on the console. If you want to do that there is probably a perl lib to handle it. The system command is supposed to quietly execute the command and return the results. If you want to display the results you can capture them by using backtics instead of the system command, and then print them, like this:
Code:
$dirlist = `dir`;
print $dirlist;
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Hi Tracy:

Somthing like this works okay

$ipInfo = `C:\\windows\\system32\\ipconfig`;
print $ipInfo;

It displays the usual information.

But, I cannot get the dir listing if I do this

$dirlist = `dir`;
print $dirlist;

Nothing is displayed at all. What am I doing wrong?
Ultimately I am trying to move files around a drive with the "move" command...but for some reason I can't seem to execute any commands that are built into cmd.exe, i.e. "move","dir" etc...


Mike L.G.
mlg400@blazemail.com
 
Mike,

Create a .cmd file, containing your move commands, within Perl and then execute that file using system(). Mike
"Experience is the comb that Nature gives us after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top