Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > pass a variable to a system call ?

Reply
Thread Tools

pass a variable to a system call ?

 
 
Jack
Guest
Posts: n/a
 
      07-14-2006
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

 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      07-14-2006
Jack wrote:
> 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


 
Reply With Quote
 
 
 
 
DJ Stunks
Guest
Posts: n/a
 
      07-14-2006

Jack wrote:
> 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

 
Reply With Quote
 
John W. Krahn
Guest
Posts: n/a
 
      07-14-2006
Jack wrote:
> 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
--
use Perl;
program
fulfillment
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Variable Input on procedure - pass by value or pass by reference? Reuven VHDL 0 03-19-2009 07:21 PM
Re: Variable Input on procedure - pass by value or pass by reference? Tricky VHDL 0 03-19-2009 03:59 PM
Variable Input on procedure - pass by value or pass by reference? Tricky VHDL 0 03-19-2009 03:58 PM
"Variable variable name" or "variable lvalue" mfglinux Python 11 09-12-2007 03:08 AM
How to pass variable argument list to another function w/ variable argument list? Ben Kial C Programming 1 11-15-2004 01:51 AM



Advertisments