[Pdx-pm] job control

Austin Schutz tex at off.org
Mon Jun 2 12:43:54 CDT 2003

On Sun, Jun 01, 2003 at 06:15:33PM -0700, Randall Hansen wrote:
> Folks ~
> I'm trying to get a list of bash's suspended jobs using Perl.  I
> initially thought this would be trivial (e.g. perl -e "print exec
> jobs"), but I've yet to succeed.  I tried permutations of "system,"
> "exec," backticks, etc.  The closest I've come is:	$ perl -e "print
> `jobs`" which apparently does an eval on the output of jobs (causing
> errors and yielding nothing useful).  But what I really want is to
> capture and examine the output, not echo it.
> It occurs to me (after seeing "No such file ..." a few times) that
> technically jobs is a builtin of bash, not a system command.  This
> hasn't gotten me any closer.  I can start a new bash with perl, but
> can't figure out how to send builtins to an existing one.
> Which in turn makes me think that this may be more of a bash question
> than a Perl one, but I thought I'd ask anyway.

	As several people have pointed out, you indeed need to communicate
with perl's parent process, or figure out a different way to accomplish what
you want.
	One way might be to have perl spawn the other processes, then send
them signals as necessary to control their behavior.
	Another way might be to use Expect.pm or Open3 to spawn bash, and
control the processes that way.
	Another way might be to use expect to spawn all the processes including
	If you must have the bash instance which spawns perl control the
processes, you will probably have to do a couple things: first, make sure
it isn't waiting on perl to return - run perl &. Then find a way for bash
to communicate with the perl process. Using named pipes would work. A bit of
a hack, but it would work.
	There are probably many other methods. What's best probably depends
on what you're working on and what method(s) you are most familiar with.


More information about the Pdx-pm-list mailing list