Home: Perl Programming Help: Beginner:
threads consume shell



jackperl
New User

Jan 6, 2013, 4:18 AM


Views: 2451
threads consume shell

Hey fellow perlers,

I'm designing a script with threads. Basically it call's some shell commands that are active all the time when running them e.g. a tail command will continue until ctrl-c is issued. I got 3 of these commands that are running through a thread because I wanted to be able to continue my script code when such a command was issued and since the script would halt at the first command it came accross, I had to use threads.

The problem is that the last thread seems to override the first threads and shows its output in the terminal but any following code that comes after the thread cannot be outputted. E.g. a simple print "foobar" won't show up in the terminal because it seems occupied by the last (never ending) command issued in the script. Is there a work around so I can output stuff in the terminal because I would want to attach a time to the script so after an x amount of time I want to sent a ctrl-c to the screen to stop the threads.
Any other way of timing a thread would be usefull also!

I already tried redirecting the output of the commands to /dev/null but then the shell just remains empty and everything seems to be redirected.

greets!


7stud
Enthusiast

Jan 13, 2013, 11:51 AM


Views: 2329
Re: [jackperl] threads consume shell


In Reply To
I already tried redirecting the output of the commands to /dev/null but then the shell just remains empty and everything seems to be redirected.

Redirect output inside each of the threads whose output you don't want to see, and don't redirect the output in the threads for which you want to see the output.

If you want more help than that, post a 15 line program that demonstrates your problem, and that anyone can run.


(This post was edited by 7stud on Jan 13, 2013, 11:53 AM)