LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 11-13-2003, 12:13 PM   #1
professorfrink
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
maddogdelta
Member
 
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
german
Member
 
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

B.
 
Old 11-13-2003, 03:02 PM   #4
professorfrink
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.

Ian
 
  


Reply


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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:19 PM.

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