Background jobs in Perl

M

Mark J Fenbers

In my Perl script, I want to launch a command and not wait for it to
return before moving on.

In a Bash script, I can do it this way:

/home/fenbers/myscript.bash &

In Perl, can I just do this:

`/home/fenbers/myscript.bash &`;

Or is there a better way of doing this?

Mark
 
M

Mark Clements

Mark said:
In my Perl script, I want to launch a command and not wait for it to
return before moving on.
In Perl, can I just do this:

`/home/fenbers/myscript.bash &`;
what happens when you try it?

Anyway: you probably want to fork and then use system or whatever in the child. perldoc
perlfork. You may also want to look at perldoc perlipc, specifically the double-fork trick.

Mark
 
B

bxb7668

I don't know which is better, but another way would be to use the
system command, i.e.
system '/home/fenbers/myscript.bash &';
 
D

David K. Wall

Mark J Fenbers said:
In my Perl script, I want to launch a command and not wait for it to
return before moving on.

perldoc -f exec

The "exec" function executes a system command *and never
returns* -- use "system" instead of "exec" if you want it to
return. It fails and returns false only if the command does not
exist *and* it is executed directly instead of via your system's
command shell (see below).

....
 
R

Robin

Mark J Fenbers said:
In my Perl script, I want to launch a command and not wait for it to
return before moving on.

In a Bash script, I can do it this way:

/home/fenbers/myscript.bash &

In Perl, can I just do this:

`/home/fenbers/myscript.bash &`;

Or is there a better way of doing this?

Mark


see the perldocs for fork. If you don't know how to run perldocs, it runs as
a program from your command line, "perldoc whatever", if you really don't
know how to run a command line operation go to perldoc.com. Although it's
still down for a few days, probably/hopefullly.

-Robin
 
P

Paul Lalli

see the perldocs for fork. If you don't know how to run perldocs, it runs as
a program from your command line, "perldoc whatever", if you really don't
know how to run a command line operation go to perldoc.com. Although it's
still down for a few days, probably/hopefullly.

For the love of $DIETY, stop trying to help people!!! Not only has this
question been answered (correctly, as opposed to your post) already, but
who in the blue hell are *you* to be telling people to read the docs when
not 10 minutes ago you admitted you STILL haven't read perldoc perlsub
after MONTHS of people telling you to!?

Paul Lalli
 

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

No members online now.

Forum statistics

Threads
474,150
Messages
2,570,853
Members
47,394
Latest member
Olekdev

Latest Threads

Top