qnx_spawn() doesn't search PATH

I am trying to use qnx_spawn() to create a child process whose
executable file is located somewhere other than the local directory from
which the parent process is invoked but is in the directory PATH (see
source code below). If I execute the following program by typing
“myspawn /bin/ls” then I get a directory listing as expected. However,
if I type “myspawn ls” then I get the error: “No such file or directory”
even though /bin is in my PATH. I tried replacing the call to
qnx_spawn() below with “pid = spawnlp (P_NOWAIT, argv[1], NULL);” and
got the same results. Has anyone attempted to do what I’m trying to do
here? Any help would be greatly appreciated.

/* myspawn.c - Parent process */

#include <stdio.h>
#include <stdlib.h>
#include <process.h>
#include <sys/qnx_glob.h>

/* argv[1] contains the command to spawn */
void
main (int argc, char **argv)
{
pid_t pid;

/* Print out PATH */

printf(“PATH=%s”, getenv(“PATH”));

pid = qnx_spawn(0, /* create a new process /
NULL, /
msgbuf /
0, /
this node*/
-1, /* priority (same as parent)/
-1, /
scheduler (same as parent)/
0, /
flags (nothing special) /
argv[1], /
cmd /
argv+1, /
argv /
environ, /
envp (same as parent) /
NULL, /
iov /
-1); /
ctfd */

printf (“Spawned task %s: %d %s\n”,
argv[1], pid, strerror(errno));

for (;:wink:
{
}
}

\

Carlos Ramirez
Senior Software Engineer
WorldGate Communications, Inc.
http://www.wgate.com

Ensure you are telling it to copy the environment instead of using a new empty environment, as the
search path is part of the environment. Or create a fresh environment with the desired setting for
search path…

Look at the spawn…() functions.
qnx_spawn() is very low level with many many options.

-Paul


Carlos Ramirez <cramirez@wgate.com> wrote in message news:3A3E4409.2C1E8828@wgate.com

I am trying to use qnx_spawn() to create a child process whose
executable file is located somewhere other than the local directory from
which the parent process is invoked but is in the directory PATH (see
source code below). If I execute the following program by typing
“myspawn /bin/ls” then I get a directory listing as expected. However,
if I type “myspawn ls” then I get the error: “No such file or directory”
even though /bin is in my PATH. I tried replacing the call to
qnx_spawn() below with “pid = spawnlp (P_NOWAIT, argv[1], NULL);” and
got the same results. Has anyone attempted to do what I’m trying to do
here? Any help would be greatly appreciated.

/* myspawn.c - Parent process */

#include <stdio.h
#include <stdlib.h
#include <process.h
#include <sys/qnx_glob.h

/* argv[1] contains the command to spawn */
void
main (int argc, char **argv)
{
pid_t pid;

/* Print out PATH */

printf(“PATH=%s”, getenv(“PATH”));

pid = qnx_spawn(0, /* create a new process /
NULL, /
msgbuf /
0, /
this node*/
-1, /* priority (same as parent)/
-1, /
scheduler (same as parent)/
0, /
flags (nothing special) /
argv[1], /
cmd /
argv+1, /
argv /
environ, /
envp (same as parent) /
NULL, /
iov /
-1); /
ctfd */

printf (“Spawned task %s: %d %s\n”,
argv[1], pid, strerror(errno));

for (;:wink:
{
}
}

\

Carlos Ramirez
Senior Software Engineer
WorldGate Communications, Inc.
http://www.wgate.com

I tried the following with the same results (i.e. No such file or directory)

spawnlp(P_NOWAIT, argv[1], NULL)
spawnl(P_NOWAIT, getenv(“PATH”), argv[1], NULL);

Paul Russell wrote:

Ensure you are telling it to copy the environment instead of using a new empty environment, as the
search path is part of the environment. Or create a fresh environment with the desired setting for
search path…

Look at the spawn…() functions.
qnx_spawn() is very low level with many many options.

-Paul

Carlos Ramirez <> cramirez@wgate.com> > wrote in message news:> 3A3E4409.2C1E8828@wgate.com> …
I am trying to use qnx_spawn() to create a child process whose
executable file is located somewhere other than the local directory from
which the parent process is invoked but is in the directory PATH (see
source code below). If I execute the following program by typing
“myspawn /bin/ls” then I get a directory listing as expected. However,
if I type “myspawn ls” then I get the error: “No such file or directory”
even though /bin is in my PATH. I tried replacing the call to
qnx_spawn() below with “pid = spawnlp (P_NOWAIT, argv[1], NULL);” and
got the same results. Has anyone attempted to do what I’m trying to do
here? Any help would be greatly appreciated.

/* myspawn.c - Parent process */

#include <stdio.h
#include <stdlib.h
#include <process.h
#include <sys/qnx_glob.h

/* argv[1] contains the command to spawn */
void
main (int argc, char **argv)
{
pid_t pid;

/* Print out PATH */

printf(“PATH=%s”, getenv(“PATH”));

pid = qnx_spawn(0, /* create a new process /
NULL, /
msgbuf /
0, /
this node*/
-1, /* priority (same as parent)/
-1, /
scheduler (same as parent)/
0, /
flags (nothing special) /
argv[1], /
cmd /
argv+1, /
argv /
environ, /
envp (same as parent) /
NULL, /
iov /
-1); /
ctfd */

printf (“Spawned task %s: %d %s\n”,
argv[1], pid, strerror(errno));

for (;:wink:
{
}
}

\

Carlos Ramirez
Senior Software Engineer
WorldGate Communications, Inc.
http://www.wgate.com


Carlos Ramirez
Senior Software Engineer
WorldGate Communications, Inc.
(215) 354-5292
http://www.wgate.com

The document examples indicate that the following is an incorrect usage:
spawnl(P_NOWAIT, getenv(“PATH”), argv[1], NULL);
Try:
spawnl(P_NOWAIT, argv[1], argv[1], NULL);
The examples documentation also indicates that the program (or a link to it)
must be in the current working directory.

Maybe you should be using system() which can shell any command line.

-Paul



Carlos Ramirez <cramirez@wgate.com> wrote in message news:3A3E5749.5358B45A@wgate.com

I tried the following with the same results (i.e. No such file or directory)

spawnlp(P_NOWAIT, argv[1], NULL)
spawnl(P_NOWAIT, getenv(“PATH”), argv[1], NULL);

Paul Russell wrote:

Ensure you are telling it to copy the environment instead of using a new empty environment, as
the
search path is part of the environment. Or create a fresh environment with the desired setting
for
search path…

Look at the spawn…() functions.
qnx_spawn() is very low level with many many options.

-Paul

Carlos Ramirez <> cramirez@wgate.com> > wrote in message news:> 3A3E4409.2C1E8828@wgate.com> …
I am trying to use qnx_spawn() to create a child process whose
executable file is located somewhere other than the local directory from
which the parent process is invoked but is in the directory PATH (see
source code below). If I execute the following program by typing
“myspawn /bin/ls” then I get a directory listing as expected. However,
if I type “myspawn ls” then I get the error: “No such file or directory”
even though /bin is in my PATH. I tried replacing the call to
qnx_spawn() below with “pid = spawnlp (P_NOWAIT, argv[1], NULL);” and
got the same results. Has anyone attempted to do what I’m trying to do
here? Any help would be greatly appreciated.

/* myspawn.c - Parent process */

#include <stdio.h
#include <stdlib.h
#include <process.h
#include <sys/qnx_glob.h

/* argv[1] contains the command to spawn */
void
main (int argc, char **argv)
{
pid_t pid;

/* Print out PATH */

printf(“PATH=%s”, getenv(“PATH”));

pid = qnx_spawn(0, /* create a new process /
NULL, /
msgbuf /
0, /
this node*/
-1, /* priority (same as parent)/
-1, /
scheduler (same as parent)/
0, /
flags (nothing special) /
argv[1], /
cmd /
argv+1, /
argv /
environ, /
envp (same as parent) /
NULL, /
iov /
-1); /
ctfd */

printf (“Spawned task %s: %d %s\n”,
argv[1], pid, strerror(errno));

for (;:wink:
{
}
}

\

Carlos Ramirez
Senior Software Engineer
WorldGate Communications, Inc.
http://www.wgate.com


\

Carlos Ramirez
Senior Software Engineer
WorldGate Communications, Inc.
(215) 354-5292
http://www.wgate.com

Actually, this turned out to be an oversight on my part. spawnlp, indeed, can spawn a process that
doesn’t live in the current working directory. The documented prototype for spawnlp is:

int spawnlp (mode, file, arg0, arg1…, argn, NULL);

I didn’t notice the ‘file’ parameter above so I was just populating arg0. I think this is a confusing
interface, however, the following does work providing argv[1] is in the directory path:

spawnlp(P_NOWAIT, argv[1], argv[1], NULL);

On another note, I was informed by QNX tech support that qnx_spawn() does not search through the
directory path. It is preferable to use the spawn…() functions instead of qnx_spawn(). If process
defaults need to be modified then qnx_spawn_options should be modified prior to calling the spawn…()
function.

Paul Russell wrote:

The document examples indicate that the following is an incorrect usage:
spawnl(P_NOWAIT, getenv(“PATH”), argv[1], NULL);
Try:
spawnl(P_NOWAIT, argv[1], argv[1], NULL);
The examples documentation also indicates that the program (or a link to it)
must be in the current working directory.

Maybe you should be using system() which can shell any command line.

-Paul

Carlos Ramirez <> cramirez@wgate.com> > wrote in message news:> 3A3E5749.5358B45A@wgate.com> …
I tried the following with the same results (i.e. No such file or directory)

spawnlp(P_NOWAIT, argv[1], NULL)
spawnl(P_NOWAIT, getenv(“PATH”), argv[1], NULL);

Paul Russell wrote:

Ensure you are telling it to copy the environment instead of using a new empty environment, as
the
search path is part of the environment. Or create a fresh environment with the desired setting
for
search path…

Look at the spawn…() functions.
qnx_spawn() is very low level with many many options.

-Paul

Carlos Ramirez <> cramirez@wgate.com> > wrote in message news:> 3A3E4409.2C1E8828@wgate.com> …
I am trying to use qnx_spawn() to create a child process whose
executable file is located somewhere other than the local directory from
which the parent process is invoked but is in the directory PATH (see
source code below). If I execute the following program by typing
“myspawn /bin/ls” then I get a directory listing as expected. However,
if I type “myspawn ls” then I get the error: “No such file or directory”
even though /bin is in my PATH. I tried replacing the call to
qnx_spawn() below with “pid = spawnlp (P_NOWAIT, argv[1], NULL);” and
got the same results. Has anyone attempted to do what I’m trying to do
here? Any help would be greatly appreciated.

/* myspawn.c - Parent process */

#include <stdio.h
#include <stdlib.h
#include <process.h
#include <sys/qnx_glob.h

/* argv[1] contains the command to spawn */
void
main (int argc, char **argv)
{
pid_t pid;

/* Print out PATH */

printf(“PATH=%s”, getenv(“PATH”));

pid = qnx_spawn(0, /* create a new process /
NULL, /
msgbuf /
0, /
this node*/
-1, /* priority (same as parent)/
-1, /
scheduler (same as parent)/
0, /
flags (nothing special) /
argv[1], /
cmd /
argv+1, /
argv /
environ, /
envp (same as parent) /
NULL, /
iov /
-1); /
ctfd */

printf (“Spawned task %s: %d %s\n”,
argv[1], pid, strerror(errno));

for (;:wink:
{
}
}

\

Carlos Ramirez
Senior Software Engineer
WorldGate Communications, Inc.
http://www.wgate.com


\

Carlos Ramirez
Senior Software Engineer
WorldGate Communications, Inc.
(215) 354-5292
http://www.wgate.com


Carlos Ramirez
Senior Software Engineer
WorldGate Communications, Inc.
(215) 354-5292
http://www.wgate.com