Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 11-13-2003, 12:13 PM   #1
LQ Newbie
Registered: Oct 2003
Location: Winnipeg Manitoba Canada
Distribution: Gentoo
Posts: 12

Rep: Reputation: 0
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
Old 11-13-2003, 12:23 PM   #2
Registered: Nov 2003
Location: tonawanda, NY
Posts: 32

Rep: Reputation: 15
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.
Old 11-13-2003, 01:03 PM   #3
Registered: Jul 2003
Location: Toronto, Canada
Distribution: Debian etch, Gentoo
Posts: 312

Rep: Reputation: 30
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

Old 11-13-2003, 03:02 PM   #4
LQ Newbie
Registered: Oct 2003
Location: Winnipeg Manitoba Canada
Distribution: Gentoo
Posts: 12

Original Poster
Rep: Reputation: 0
Thanks for clearing that up guys.
I'll go through the man page.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help: Perl or Bash Script help embsupafly Programming 1 08-11-2005 06:01 PM
Bash script - to save and run a command at the end satimis Programming 15 11-02-2004 08:53 AM
run command in background using C syberdave Programming 3 04-03-2004 06:43 AM
bash script to accept input ONLY until background process completes andrewstr Linux - Software 2 03-17-2004 12:02 PM
How to Run perl scripts using bash Boudewijn Linux - Software 2 11-26-2003 03:37 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:33 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration