pass a variable to a system call ?

J

Jack

Ok this is annoying.. I tried the code below tons of different ways,
even with double quotes " " with no luck.. how do I pass a variable
into a system call ??!!

$filename = 'FileList.txt';
system("dir /B c:\test_files > c:\test_files\".$filename);

... OR ...

$filename = 'FileList.txt';
system('dir /B c:\test_files > c:\test_files\'.$filename);

Any ideas ??

Thank you,
Jack
 
J

Jürgen Exner

Jack said:
Ok this is annoying.. I tried the code below tons of different ways,
even with double quotes " " with no luck.. how do I pass a variable
into a system call ??!!

$filename = 'FileList.txt';
system("dir /B c:\test_files > c:\test_files\".$filename);

For example exactly that way.
However, are you certain that the first character of your folder name is a
TAB character?
And the escaped closing double quote yields a
Can't find string terminator '"' anywhere before EOF at t.pl
when I try it.
.. OR ...

$filename = 'FileList.txt';
system('dir /B c:\test_files > c:\test_files\'.$filename);

Same error here. Why do you escape the closing single quote?
Any ideas ??

Yep. Use normal forward slashes to avoid the leaning toothpick syndrome.

jue
 
D

DJ Stunks

Jack said:
Ok this is annoying.. I tried the code below tons of different ways,
even with double quotes " " with no luck.. how do I pass a variable
into a system call ??!!

$filename = 'FileList.txt';
system("dir /B c:\test_files > c:\test_files\".$filename);

.. OR ...

$filename = 'FileList.txt';
system('dir /B c:\test_files > c:\test_files\'.$filename);

Any ideas ??

yes, I have some ideas.

first idea: have you looked at perldoc -f system and, for good
measure, perldoc -f exec?

second idea: do you understand how interpolation works in a double
quoted string? particularly with regard to backslashes?

third (and final) idea: did you know Perl isn't a glorified shell
scripting language or batch file replacement? if you want a directory
listing as part of another, more complicated script, usually the best
idea is using a Perl module to grab the information rather than
shelling out to dir.

HTH,
-jp
 
J

John W. Krahn

Jack said:
Ok this is annoying.. I tried the code below tons of different ways,
even with double quotes " " with no luck.. how do I pass a variable
into a system call ??!!

$filename = 'FileList.txt';
system("dir /B c:\test_files > c:\test_files\".$filename);

.. OR ...

$filename = 'FileList.txt';
system('dir /B c:\test_files > c:\test_files\'.$filename);

Any ideas ??

It looks like you need something like:

my $filename = 'FileList.txt';
my $dir = 'c:/test_files';

open my $fh, '>', "$dir/$filename" or die "Cannot open '$dir/$filename' $!";

opendir my $dh, $dir or die "Cannot open '$dir' $!";

print $fh map "$_\n", readdir $dh;

closedir $dh;
close $fh;



John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top