The assignment of command output to an array hangs.

K

kaleem

Hello,

I've got a function in a package which I use to call system commands.
Inside this function
I've got the following code:

@results = `$command`; # $command is the system command to run

My problem is that this function (and the piece of code above) works
fine but it fails for
a particular command. It just hangs. The command which I'm calling is
actually a KornShell
script. I've verified that this script itself does not hang. I tried to
use -d option to debug and I
observed that the script hangs at the line shown above. Strangely, when
I ran the same code
using 'perl -e' it works! What I did was that I assigned the command to
$command and then
just put the same code as shown above. It worked with 'perl -e'.

Please let me know how can I debug this problem further.

Your responses will be greatly appreciated.

Thanks.
Kaleem.
 
P

Paul Lalli

kaleem said:
Hello,

I've got a function in a package which I use to call system commands.
Inside this function
I've got the following code:

@results = `$command`; # $command is the system command to run

My problem is that this function (and the piece of code above) works
fine but it fails for
a particular command. It just hangs. The command which I'm calling is
actually a KornShell
script. I've verified that this script itself does not hang. I tried to
use -d option to debug and I
observed that the script hangs at the line shown above. Strangely, when
I ran the same code
using 'perl -e' it works! What I did was that I assigned the command to
$command

How? Are you confident $command contains what you think it does?
and then
just put the same code as shown above. It worked with 'perl -e'.

You're asking us to trust that the code in your file is exactly the
same as the code in your -e'' script. I don't. Please post a
short-but-complete script that demonstrates your error.
Please let me know how can I debug this problem further.

Step one would be printing out $command to verify that it is what you
think it is. Did you think about newlines and chomping them? We have
no idea what your actual code is like, so it's nigh impossible to help
you debug it.

Paul Lalli.
 
K

kaleem

Thanks for respoding Paul. Please note that I'm not a novice and I'm
sure of what I'm
saying. I mean I have checked all these things which you are asking me
to check.
Also, on further investigation I've found that after the KornShell
script completes,
it becomes defunct (zombie). It means that its parent hasn't waited for
it. When
I terminate the Perl script, this zombie process goes away.

This is what my code looks like:

cmd ("/abc/xyz/def 2>&1");

/abc/xyz/def is a KornShell script.

The cmd looks like this:

sub cmd
{
$command = shift;

.....

@results = `$command`
....

}

Please note that the same code works if I just call /abc/xyz/def using
cmd in
another Perl script or using 'perl -e'. My actual script has lots of
other code in addtition to calling /abc/xyz/def.

Let me know what you think.

Regards,
Kaleem.
 
P

Paul Lalli

kaleem said:
Thanks for respoding Paul. Please note that I'm not a novice and I'm
sure of what I'm
saying. I mean I have checked all these things which you are asking me
to check.
Also, on further investigation I've found that after the KornShell
script completes,
it becomes defunct (zombie). It means that its parent hasn't waited for
it. When
I terminate the Perl script, this zombie process goes away.

This is what my code looks like:

cmd ("/abc/xyz/def 2>&1");

/abc/xyz/def is a KornShell script.

The cmd looks like this:

sub cmd
{
$command = shift;

....

@results = `$command`
...

}

Please note that the same code works if I just call /abc/xyz/def using
cmd in
another Perl script or using 'perl -e'. My actual script has lots of
other code in addtition to calling /abc/xyz/def.

Let me know what you think.

I think you're very arrogant to assume that you have not made any
mistakes, novice or expert. I asked you to post a short-but-complete
script that we can run to test your problem, and you instead gave me
pseudo code that simply restated what you said in your first post. You
seem to be wanting us to come back and say "yup, there's a bug in Perl"
rather than to actually help you diagnose what you may have done wrong.

Do you want a solution to your problem, or do you want to avoid
bruising your ego?

Paul Lalli

P.S. And to those who think this post was rude, yes it was. But in my
opinion not undeservingly so.
 
K

kaleem

You are crude, Paul. Please don't ever reply to my any further
postings. I never suggested
that Perl had a bug or that I wanted you to come back and tell me that
Perl had a bug. All I
wanted to know was how to debug problem further. If I could provide
code as it is I could
have done it earlier.

Thanks for being so nice.

Paul said:
I think you're very arrogant to assume that you have not made any
mistakes, novice or expert. I asked you to post a short-but-complete
script that we can run to test your problem, and you instead gave me
pseudo code that simply restated what you said in your first post. You
seem to be wanting us to come back and say "yup, there's a bug in Perl"
rather than to actually help you diagnose what you may have done wrong.

Do you want a solution to your problem, or do you want to avoid
bruising your ego?

Paul Lalli

P.S. And to those who think this post was rude, yes it was. But in my
opinion not undeservingly so.

You are crude, Paul. Please don't ever reply to my any further
postings. I never suggested
that Perl had a bug or that I wanted you to come back and tell me that
Perl had a bug. All I
wanted to know was how to debug problem further. If I could provide
code as it is I could
have done it earlier.

Thanks for being so nice.

Paul Lalli wrote:
 
P

Paul Lalli

kaleem said:
You are crude, Paul. Please don't ever reply to my any further postings.

Sorry, you don't get to make that decision. If you don't want to see
my posts, killfile me.
I never suggested
that Perl had a bug or that I wanted you to come back and tell me that
Perl had a bug. All I
wanted to know was how to debug problem further.

And I told you exactly how to do that! You create a short-but-complete
script that exhibits the problem. If your short-but-complete script
doesn't exhibit the problem, then you figure out what you did
differently between the short script and the "real" script.
If I could provide code as it is I could have done it earlier.

You could have, but you didn't. Hence the problem. You want to know
how to debug your program, but you don't want to actually put any
effort into debugging your program.

Paul Lalli
 
M

Mumia W.

Thanks for respoding Paul. Please note that I'm not a novice and I'm
sure of what I'm
saying. I mean I have checked all these things which you are asking me
to check.
Also, on further investigation I've found that after the KornShell
script completes,
it becomes defunct (zombie). It means that its parent hasn't waited for
it. When
I terminate the Perl script, this zombie process goes away.

This is what my code looks like:

cmd ("/abc/xyz/def 2>&1");

/abc/xyz/def is a KornShell script.

The cmd looks like this:

sub cmd
{
$command = shift;

.....

@results = `$command`
....

}

Please note that the same code works if I just call /abc/xyz/def using
cmd in
another Perl script or using 'perl -e'. My actual script has lots of
other code in addtition to calling /abc/xyz/def.

Let me know what you think.

Regards,
Kaleem.

Please don't top-post.

Your script is changing the environment such that your "def"
script won't run correctly. Print out the environment
variables for both successful and unsuccessful runs and
compare them.
 
B

Brian McCauley

kaleem said:
I've found that after the KornShell script completes,
it becomes defunct (zombie). It means that its parent hasn't waited for
it.

Right. IIRC readpipe() (aka qx aka `` ) will first wait for an EOF
condition on the FIFO and then wait() for the exit status of the
subprocess.

The symptoms you describe indicate that most likely your subrocess has
performed a fork-off-and-die without remebering to close (or redirect)
STDOUT in the child.

I can trivially reproduce the symptoms you are experiencing thus

$ perl -e'`sleep 30 &`'

The /bin/sleep process is still holding the FIFO open so the /bin/sh
becomes a zombie for 30 seconds.
 
K

kaleem

Hey Brian,

You seem to be the sensible (and technically adept) one here.:) The
other two people who replied to my post seemed to be full of hubris and
technically incompetent (trying to hide their incompetency asking me
silly questions).

Well, as I wrote, this problem is reproducible only in this particular
case, I mean only in this particular Perl script of mine. In this
script I have other code before this piece of code
is executed where it hangs. If I created another Perl script which just
has the problem code (the piece of code which hangs) it works fine! So
it seems it might be a KornShell problem. Well, I'll try to look more
into this and will get back. Thanks for respoding, man.

Regards,
Kaleem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top