Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

How to avoid to launch a unix shell script in a perl script

by bertigo (Novice)
on May 06, 2008 at 08:42 UTC ( [id://684886]=perlquestion: print w/replies, xml ) Need Help??

bertigo has asked for the wisdom of the Perl Monks concerning the following question:

I try to avoid to use this line in a perl script : system('nohup ./enter.sh &'); On the following lines, the perl script check the log file created by enter.sh script: cmd_proc_shell "enter 0,1,0" In interactive mode the cmd_proc_shell command only finish with a control-C. I have tried to use these two possibilities 1- open (F,"cmd_proc_shell \"enter 0,1,0\"" 2- system "cmd_proc_shell","\"enter","0,1,0","\"" but it doesn't work. Thans for any reply

Replies are listed 'Best First'.
Re: How to avoid to launch a unix shell script in a perl script
by ikegami (Patriarch) on May 06, 2008 at 09:13 UTC

    I'm confused. Are you having a problem running enter.sh or cmd_proc_shell? It sounds like you are having problems with latter, but then there'd be no reason to mention the former.

    Assuming your problem is with cmd_proc_shell, how do you want to run it? Specifically, do you need to capture its output, do you need to know its error code, do you want to wait for it to finish running before continuing, and are you on a Windows system or not?

    If you don't need to capture its output and you don't mind waiting for it to finish running before continuing,

    Unix: system('cmd_proc_shell', 'enter 0,1,0'); Windows system('cmd_proc_shell "enter 0,1,0"');

    In unix, the quotes you passed to the shell aren't seen by the program. The shell splits the command into arguments, unquotes everything, and passes the arguments as an array. In Windows, it's the program's responsibility to handle its own command line parsing.

      The script run on unix; the cmd_proc_shell has to be launched on background otherwise the command wait a CTRL-C. I don't need to capture the output nor the error code.
        fork || exec("cmd_proc_shell");
Re: How to avoid to launch a unix shell script in a perl script
by moritz (Cardinal) on May 06, 2008 at 08:55 UTC
    Why do you want to avoid it? And what do you want to do instead? Emulate the contents of enter.sh in your perl script? Or use another way to start enter.sh in the background? (you can achieve that with fork and exec)
Re: How to avoid to launch a unix shell script in a perl script
by ambrus (Abbot) on May 07, 2008 at 12:08 UTC

    Search for "background" in perlfaq8 and in perlipc on how to launch a subprocess in the background. If you read carefully, these perldocs also tell you how to make the subprocess lose its controlling terminal and redirect its output to a file, which is what nohup does.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://684886]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-03-29 09:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found