LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to run a bash command in the background from perl script (https://www.linuxquestions.org/questions/programming-9/how-to-run-a-bash-command-in-the-background-from-perl-script-115635/)

professorfrink 11-13-2003 12:13 PM

How to run a bash command in the background from perl script
 
HI All,

I have a perl script that checks to see if the tape drive is on and sends a message to a windows machine and a Linux machine if it finds any problem.

I use smbclient to send the message to the windows machine. No Problem.

I am using xmessage to send the message to the linux machine.

I need xmessage to run in the background and continue on with the rest of the script.

From the command line I would just do something like this:

xmessage -display pos:1 "Error message here..." &

The ampersand (&) at the end would put the process into the background.

My perl script seems to ignore this character and therefore not put the xmessage program in the background. It is called like this:

<some perl code here>
`xmessage -display pos1:0 "Error message here" &`;
<more perl code here>

can anyone help?

Thanks, Ian

maddogdelta 11-13-2003 12:23 PM

I'm currently not at a machine wih perl on it, but I do have Perl in a Nutshell. (I'm not a geek, but I do play one on TV!).

Have you tried threads? I don't know if the following code will work, but it may be worth a try:
use Thread qw/async/;

$val = async {
`xmessage -display pos1:0 "Error message here" &`;
};
with $val now containing a thread object that you can probably safely ignore.

Don't forget the semi after the closing brace.

german 11-13-2003 01:03 PM

yes, you're trying to use rudimentary shell script threading, from perl, which won't really work. Either re-make your script as a bash/sh/ksh script, or use perl threading ("man perlthrtut" is a whole tutorial on it). Hope that helpsa person blehergen GLAVEN

B.

professorfrink 11-13-2003 03:02 PM

Thanks for clearing that up guys.
I'll go through the man page.

Ian


All times are GMT -5. The time now is 05:47 AM.