Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^4: System() in list mode?

by 1337John (Initiate)
on Oct 17, 2011 at 21:49 UTC ( #932019=note: print w/ replies, xml ) Need Help??


in reply to Re^3: System() in list mode?
in thread System() in list mode?

So then how would you use system() if your program's path name has spaces in it?


Comment on Re^4: System() in list mode?
Re^5: System() in list mode?
by onelesd (Pilgrim) on Oct 17, 2011 at 21:58 UTC

    You can use $WHAT in foo.sh like this. Notice the space.

    system('env', 'WHAT=bar', '/Users/onelesd/Work/space/a space/foo.sh') ;

      But I can't use PATH... Which makes no sense if there is absolutely no shell interaction. I also do notice that space, that's exactly why I'm trying to get this working. The problem I have is setting an environment variable called PATH because my script uses it. I don't really care much for a variable called WHAT. And rewriting the script is not an option.

      P.s. thanks for the help so far!

        So replace WHAT with PATH and your script will see $PATH just fine. I used WHAT because the name of the variable does not matter since you are not using a shell in LIST mode, and PATH has no more special meaning than WHAT does.

        Beyond that, the only problem I see in your posted code is that you don't give a full path to /bin/bash (and $path isn't defined, but maybe you did that elsewhere).

        Which makes no sense if there is absolutely no shell interaction

        That's not exactly correct. Remember the magic of Perl---the impossible is always possible. Here's an example. It requires: IPC::System::Simple.
        !/usr/bin/perl -l use strict; use warnings; use IPC::System::Simple qw(capturex systemx); my $PATH = $ENV{'PATH'}; my $SHELL = $ENV{'SHELL'}; my $path = '/root/Desktop/test a folder/this script.sh'; my @arr1 = ( "printenv", "PATH" ); capturex(@arr1); my @arr2 = ( "echo", "$PATH" ); systemx(@arr2); my @arr3 = ("$SHELL", "$path"); my @script = system(@arr3);

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://932019]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2014-09-16 09:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (158 votes), past polls