Operating System - HP-UX
1748252 Members
3967 Online
108760 Solutions
New Discussion юеВ

Re: system() command fails on HP-UX PARISC 11iv3

 
ShikhaMaheshwari
New Member

system() command fails on HP-UX PARISC 11iv3

Hi,
when we execute system() command (as follows) in the application, it gives following error:

command syntax used in application code:
system ("ps -eaf | grep ssh");

error:
sh: ps: not found.
sh: grep: not found.

But if I test this with a sample program as:
#include
#include

int main()
{
system ("ps -eaf | grep ssh");
return 0;
}

It works fine.
Can anyone tell, what could be the reasons of the failure and why does it show different behavior?

NOTE: In application we are not doing any such operation which can disturb the shell environment.

Other Information:
------------------
# uname -a
HP-UX islrppss B.11.31 U 9000/800 936132380 unlimited-user license

# aCC -V
aCC: HP ANSI C++ B3910B A.03.80
10 REPLIES 10
Steven Schweda
Honored Contributor

Re: system() command fails on HP-UX PARISC 11iv3

> sh: ps: not found.

Apparently, system() is running "sh" as it
should, but "sh" is not finding "ps". I'd
guess that there's a problem with PATH in the
problem environment.

An easy (if not very portable) way out might
be to specify absolute paths to "ps" and
"grep" in your argument string.

To explore, you might throw in something
like:

system( "echo $PATH");

and see what that says.
James R. Ferguson
Acclaimed Contributor

Re: system() command fails on HP-UX PARISC 11iv3

Hi:

This suggests that your application's PATH doesn't contain '/usr/bin'.

You might fix your application to do"

# system ("/usr/bin/ps -eaf | grep /usr/bin/ssh");

...instead of:

# system ("ps -eaf | grep ssh");

Regards!

...JRF...

Steven Schweda
Honored Contributor

Re: system() command fails on HP-UX PARISC 11iv3

> # system ("/usr/bin/ps -eaf | grep /usr/bin/ssh");

That may not help it to find "grep", but it
could damage basic functionality. (If you've
seen one path, you've seen them all, I always
say.)
James R. Ferguson
Acclaimed Contributor

Re: system() command fails on HP-UX PARISC 11iv3

Hi (again):

OK, stupid typo as Steven pointed out:

I wrote:

# system ("/usr/bin/ps -eaf | grep /usr/bin/ssh");

But should have written:

# system ("/usr/bin/ps -eaf | /usr/bin/grep /usr/bin/ssh");

...JRF...
Dennis Handly
Acclaimed Contributor

Re: system() command fails on HP-UX PARISC 11iv3

>system ("ps -eaf | grep ssh");

As an optimization, you could toss that grep:
system("UNIX95=EXTENDED_PS /usr/bin/ps -af -C ssh")
Provided you don't care about -a exclusions.
Otherwise you might want to use: /usr/bin/grep -w ssh
Steven Schweda
Honored Contributor

Re: system() command fails on HP-UX PARISC 11iv3

> OK, stupid typo [...]

Not every error is a typographical error.

> But should have written:
>
> # system ("/usr/bin/ps -eaf | /usr/bin/grep /usr/bin/ssh");

Why "/usr/bin/ssh" instead of "ssh"?
James R. Ferguson
Acclaimed Contributor

Re: system() command fails on HP-UX PARISC 11iv3

Hi (again):

> Steven: Why "/usr/bin/ssh" instead of "ssh"?

OMG, I have failed to multitask during dinner :-( Yes, yes, I mean use *absolute* paths to your executables' only (although that should have been somewhat obvious from my *first* post's commentary (minus the bungled code corrected below):

# system ("/usr/bin/ps -eaf | /usr/bin/grep ssh");

Regards!

...JRF...
ShikhaMaheshwari
New Member

Re: system() command fails on HP-UX PARISC 11iv3

Hi,

Thanks for your reply.

yes, it works in the following way:
system("/usr/bin/ps -eaf|/usr/bin/grep ssh");

But I do not want to use in this way. It works fine on other platforms(Liux, Solaris) in the same way but not on HP.

As per your suggestion, I printed PATH before calling system() in the application code as:

system("echo $PATH");
system("ps -eaf|grep ssh");

PATH shows the correct output. It has all the required ones like:

/usr/ccs/bin:/usr/contrib/bin:/usr/contrib/Q4/bin:/opt/perl/bin:/usr/sbin:/usr/bin:/opt/ansic/bin:/usr/ccs/bin:/usr/contrib/bin:/usr/contrib/Q4/bin:/opt/perl/bin:/opt/ipf/bin:/opt/nettladm/bin:/opt/fcms/bin:/opt/wbem/bin:/opt/firefox:/opt/gnome/bin:.....

Then also the error occurs.
sh : ps : not found
sh : grep : not found

It would be highly appreciable if anyone can help me to find out the root cause of this failure.

Many Thanks in advance.

-Shikha
Dennis Handly
Acclaimed Contributor

Re: system() command fails on HP-UX PARISC 11iv3

>It works fine on other platforms in the same way but not on HP-UX.

You said it worked in a small example, so there is something special about your application.

>I printed PATH before calling system() in the application code as:
system("echo $PATH");
system("ps -eaf|grep ssh");

Hmm, that seems right.

>It has all the required ones like:
/usr/ccs/bin:/usr/contrib/bin:/usr/contrib/Q4/bin:/opt/perl/bin:/usr/sbin:/usr/bin:...

You may want to put /usr/bin first.

>It would be highly appreciable if anyone can help me to find out the root cause of this failure.

Unfortunately it seems you need to be looking for zebras. ;-)

You could use tusc to see what your application is doing with the environ(5):
tusc -fp -ea -o tusc.out application parms ...

And attach the resulting tusc.out if it isn't too big.
Otherwise look for sections doing fork/exec of /usr/bin/sh.