system() returns -1???

Okay, since I can’t use a perl script for my print filter, I tried to
write it in C++. This is all I’m doing:

sprintf(zSystemCommand, “/usr/bin/phs-to-ps -od %s > %s”, zPHSFileName,
zPSFileName);
iRetCode = system(zSystemCommand);
cout << "Error: " << errno << endl;

system() returns -1, meaning it can’t start the shell.
errno is 2, no such file or directory.

/bin/sh is there. What’s going on?

hamtaro@hotmail.com sed in <bmjfmq$ad5$1@inn.qnx.com>:

system() returns -1, meaning it can’t start the shell.

What does system(NULL) return?

If it ain’t zero, the installation itself could be screwed elsewhere.

(Using 6.1 libc on 6.2.1 nto may cause this, but I can’t reproduce it)

kabe

kabe@sra-tohoku.co.jp wrote:

hamtaro@hotmail.com > sed in <bmjfmq$ad5$> 1@inn.qnx.com> >:


system() returns -1, meaning it can’t start the shell.


What does system(NULL) return?

system(NULL) is returning 1! Great. What could possibly be wrong with
the installation?

hamtaro@hotmail.com sed in <bmmadi$c1q$1@inn.qnx.com>:

system(NULL) is returning 1! Great. What could possibly be wrong with
the installation?

Sorry I’ve made a horrible error, returning 1 is correct.
it returns zero for f*cked environment
URL:http://www.qnx.com/developer/docs/momentics621_docs/neutrino/lib_ref/s/system.html

Probably directly using spawn() (not spawn*() series) may reveal something.

kabe
P.S Is physical memory enough? spawn() may fail if mem is short.

kabe@sra-tohoku.co.jp wrote:

hamtaro@hotmail.com > sed in <bmmadi$c1q$> 1@inn.qnx.com> >:


system(NULL) is returning 1! Great. What could possibly be wrong with
the installation?


Sorry I’ve made a horrible error, returning 1 is correct.

Ah, okay. That’s a load off my mind.

Seems the output redirect “>” in my system() command is what’s causing
the trouble. I need the output redirected to a file, or redirected to
the program’s stdin. I guess this is more of a generic C/C++ question…

Roger Smith <hamtaro@hotmail.com> wrote:
RS > kabe@sra-tohoku.co.jp wrote:

hamtaro@hotmail.com > sed in <bmmadi$c1q$> 1@inn.qnx.com> >:


system(NULL) is returning 1! Great. What could possibly be wrong with
the installation?


Sorry I’ve made a horrible error, returning 1 is correct.

RS > Ah, okay. That’s a load off my mind.

RS > Seems the output redirect “>” in my system() command is what’s causing
RS > the trouble. I need the output redirected to a file, or redirected to
RS > the program’s stdin. I guess this is more of a generic C/C++ question…


Look at popen() instead of system().

Bill Caroselli wrote:

Look at popen() instead of system().

Interesting idea, thanks.

I’d like to use streams, though. How would I utilize the FILE pointer
from popen() in an “ifstream” situation. “getline” is just too handy.

On Thu, 16 Oct 2003 16:37:16 -0400, Roger Smith wrote:

Bill Caroselli wrote:

Look at popen() instead of system().

Interesting idea, thanks.

I’d like to use streams, though. How would I utilize the FILE pointer
from popen() in an “ifstream” situation. “getline” is just too handy.

If you are using GNU libs you can just do

FILE *fp = popen(…);
ifstream mystream(fileno(fp));

but this is probably a bit dodgy since the thing you are treating as an
ifstream is a pipe and so doesn’t really have file semantics.

In any case if you are using Dinkum (or worry about standards conformance)
it looks like you are SOL since there is no ifstream(fd) constructor. I
guess you could write your own iostream-derived class to handle it (which
is actually easier than it sounds).

Or if you don’t need cin elsewhere in your program the following kludge
should work to “tie” cin to your pipe:

close(fileno(stdin));
FILE *fp = popen(…); // Will use first unused fd ie 0=stdin=cin
// cin is now connected to your pipe, you can just do
cin.get_line();

There may be a “proper” way of doing this?

Just a few ideas…

Rob Rutherford