Process vs Process

Hi,

Is there any function or trick to start a process from another process,
which has not a
string literal (<const char *>) as the parameter for the file name that
contains the process to execute???

If the answer is negative, how is the best way to achieve it then?

Thanks,

JcD

Well I’m not sure I understand exactly what you’re after, but your choices are:
the spawn() family, system(), or fork() plus the exec() family. Perhaps browse
the documentation and see if any of those will meet your needs.

-Warren


“juan carlos” <jcd@dcs.st-and.ac.uk> wrote in message
news:8uu8oa$cmb$1@inn.qnx.com
| Hi,
|
| Is there any function or trick to start a process from another process,
| which has not a
| string literal (<const char *>) as the parameter for the file name that
| contains the process to execute???
|
| If the answer is negative, how is the best way to achieve it then?
|
| Thanks,
|
| JcD
|
|

Thanks Warren,

but all of these (not fork()) take a string literal, that is, a const char*
as a parameter for the name of the file that I want to execute but what I
need instead it’s to pass an instance or variable that contains the file
name.

i.e.
spawnl(P_NOWAITO,“MyServer”, “MyServer”, “shot”, NULL);
that executes ok, but I need


char Cell[10];


at same point from somewhere Cell got the string “shot”

spawnl(P_NOWAITO,“MyServer”, “MyServer”, Cell, NULL);
that doesn’t work.


Cheers

JcD


“Warren Peece” <warren@nospam.com> wrote in message
news:8uu9k3$dpj$1@inn.qnx.com

Well I’m not sure I understand exactly what you’re after, but your choices
are:
the spawn() family, system(), or fork() plus the exec() family. Perhaps
browse
the documentation and see if any of those will meet your needs.

-Warren


“juan carlos” <> jcd@dcs.st-and.ac.uk> > wrote in message
news:8uu8oa$cmb$> 1@inn.qnx.com> …
| Hi,
|
| Is there any function or trick to start a process from another process,
| which has not a
| string literal (<const char *>) as the parameter for the file name that
| contains the process to execute???
|
| If the answer is negative, how is the best way to achieve it then?
|
| Thanks,
|
| JcD
|
|

juan carlos <jcd@dcs.st-and.ac.uk> wrote:

Thanks Warren,

but all of these (not fork()) take a string literal, that is, a const char*
as a parameter for the name of the file that I want to execute but what I
need instead it’s to pass an instance or variable that contains the file
name.

i.e.
spawnl(P_NOWAITO,“MyServer”, “MyServer”, “shot”, NULL);
that executes ok, but I need



char Cell[10];

How do you write to Cell? Try using sprintf, something like
sprintf(Cell,"%s",“shot”);

at same point from somewhere Cell got the string “shot”

spawnl(P_NOWAITO,“MyServer”, “MyServer”, Cell, NULL);
that doesn’t work.



Cheers

JcD



“Warren Peece” <> warren@nospam.com> > wrote in message
news:8uu9k3$dpj$> 1@inn.qnx.com> …
Well I’m not sure I understand exactly what you’re after, but your choices
are:
the spawn() family, system(), or fork() plus the exec() family. Perhaps
browse
the documentation and see if any of those will meet your needs.

-Warren


“juan carlos” <> jcd@dcs.st-and.ac.uk> > wrote in message
news:8uu8oa$cmb$> 1@inn.qnx.com> …
| Hi,
|
| Is there any function or trick to start a process from another process,
| which has not a
| string literal (<const char *>) as the parameter for the file name that
| contains the process to execute???
|
| If the answer is negative, how is the best way to achieve it then?
|
| Thanks,
|
| JcD
|
|

juan carlos <jcd@dcs.st-and.ac.uk> wrote:

Hi,

Is there any function or trick to start a process from another process,
which has not a
string literal (<const char *>) as the parameter for the file name that
contains the process to execute???

I think you misunderstand the meaning of the <const char *> for the
parameter – that doesn’t mean the parameter has to be a constant string.
That means that the function will not change the string, that is, that
the code inside the function must treat that string as a constant.

You can easily do something like:

char buffer[512];

sprintf(buffer, “%s%d”, progname, prog_instance);
spawn*(…, buffer, … );

-David

You can stuff a character array (or character pointer) in there wherever you
see a “const char *” definition. In a function prototype, I believe all the
const part means is that the function isn’t going to alter anything you pass
in to it. Just stuff the name you want into “Cell” and example #2 should
work fine.

-Warren


“juan carlos” <jcd@dcs.st-and.ac.uk> wrote in message
news:8uunr2$r63$1@inn.qnx.com

Thanks Warren,

but all of these (not fork()) take a string literal, that is, a const
char*
as a parameter for the name of the file that I want to execute but what I
need instead it’s to pass an instance or variable that contains the file
name.

i.e.
spawnl(P_NOWAITO,“MyServer”, “MyServer”, “shot”, NULL);
that executes ok, but I need


char Cell[10];


at same point from somewhere Cell got the string “shot”

spawnl(P_NOWAITO,“MyServer”, “MyServer”, Cell, NULL);
that doesn’t work.


Cheers

JcD


“Warren Peece” <> warren@nospam.com> > wrote in message
news:8uu9k3$dpj$> 1@inn.qnx.com> …
Well I’m not sure I understand exactly what you’re after, but your
choices
are:
the spawn() family, system(), or fork() plus the exec() family. Perhaps
browse
the documentation and see if any of those will meet your needs.

-Warren


“juan carlos” <> jcd@dcs.st-and.ac.uk> > wrote in message
news:8uu8oa$cmb$> 1@inn.qnx.com> …
| Hi,
|
| Is there any function or trick to start a process from another
process,
| which has not a
| string literal (<const char *>) as the parameter for the file name
that
| contains the process to execute???
|
| If the answer is negative, how is the best way to achieve it then?
|
| Thanks,
|
| JcD
|
|
\

Heh. Yeah, what he said!


“David Gibbs” <dagibbs@qnx.com> wrote in message
news:8uv5lc$eb2$1@nntp.qnx.com

juan carlos <> jcd@dcs.st-and.ac.uk> > wrote:
Hi,

Is there any function or trick to start a process from another process,
which has not a
string literal (<const char *>) as the parameter for the file name that
contains the process to execute???

I think you misunderstand the meaning of the <const char *> for the
parameter – that doesn’t mean the parameter has to be a constant string.
That means that the function will not change the string, that is, that
the code inside the function must treat that string as a constant.

You can easily do something like:

char buffer[512];

sprintf(buffer, “%s%d”, progname, prog_instance);
spawn*(…, buffer, … );

-David

Hi,

Thanks you all Warren, David & Marcin.

I tell you what was the ghost!!! enjoy it!

You were all right!. I thought exactly as David, that is, const char * means
that the function internally takes the parameter as a constant. Well, for
that reason I did strcpy(), strcat, sprintf()… etc… to get the stuff
into the so called Cell variable. As I said the C program ran fine, but the
child process was complaining about the file name.

After displaying out about 3,000,000,000 Million times :slight_smile: what was inside
Cell was the “right” stuff and posting here for help …

the problem was just a no visible character on the screen, a fuc…’/n’
that came at the end of a string that my program sucks from a common buffer
in the network (nobody told me about that ‘/n’!!) and then it was
concatenated at the end of Cell!! i.e.

Cell ="Hello "
Buffer=“World’/n’”
Cell+Buffer=“Hello World/n”

So you see
Hello World

… and everything seems to be ok, till you do a strlen(Buffer) and
oopsss!!!

The thing became complicated when I counted wrongly and thought strlen() was
ok!!! from that point I started to space out.

Sorry about that folks! It was one of those days… :slight_smile:

JcD




“David Gibbs” <dagibbs@qnx.com> wrote in message
news:8uv5lc$eb2$1@nntp.qnx.com

juan carlos <> jcd@dcs.st-and.ac.uk> > wrote:
Hi,

Is there any function or trick to start a process from another process,
which has not a
string literal (<const char *>) as the parameter for the file name that
contains the process to execute???

I think you misunderstand the meaning of the <const char *> for the
parameter – that doesn’t mean the parameter has to be a constant string.
That means that the function will not change the string, that is, that
the code inside the function must treat that string as a constant.

You can easily do something like:

char buffer[512];

sprintf(buffer, “%s%d”, progname, prog_instance);
spawn*(…, buffer, … );

-David

“juan carlos” <jcd@dcs.st-and.ac.uk> wrote in message
news:8v18la$edf$1@inn.qnx.com
| Hi,
|
| Thanks you all Warren, David & Marcin.
|
| I tell you what was the ghost!!! enjoy it!
|
| You were all right!. I thought exactly as David, that is, const char * means
| that the function internally takes the parameter as a constant. Well, for
| that reason I did strcpy(), strcat, sprintf()… etc… to get the stuff
| into the so called Cell variable. As I said the C program ran fine, but the
| child process was complaining about the file name.
|
| After displaying out about 3,000,000,000 Million times :slight_smile: what was inside
| Cell was the “right” stuff and posting here for help …
|
| the problem was just a no visible character on the screen, a fuc…’/n’
| that came at the end of a string that my program sucks from a common buffer
| in the network (nobody told me about that ‘/n’!!) and then it was
| concatenated at the end of Cell!! i.e.
|
| Cell ="Hello "
| Buffer=“World’/n’”
| Cell+Buffer=“Hello World/n”
|
| So you see
| Hello World
|
| … and everything seems to be ok, till you do a strlen(Buffer) and
| oopsss!!!
|
| The thing became complicated when I counted wrongly and thought strlen() was
| ok!!! from that point I started to space out.
|
| Sorry about that folks! It was one of those days… :slight_smile:
|
| JcD

Glad you got it fixed. I had one of those days today, compounded by the fact
that I had one too many at the hockey game last night… :slight_smile:

-Warren

juan carlos <jcd@dcs.st-and.ac.uk> wrote:

Hi,
the problem was just a no visible character on the screen, a fuc…’/n’
that came at the end of a string that my program sucks from a common buffer
in the network (nobody told me about that ‘/n’!!) and then it was
concatenated at the end of Cell!! i.e.

Are you sure it wasn’t a ‘\n’ – that is a newline character? Anyway,
glad you figured things out.

-David

Cell ="Hello "
Buffer=“World’/n’”
Cell+Buffer=“Hello World/n”

So you see
Hello World

… and everything seems to be ok, till you do a strlen(Buffer) and
oopsss!!!

The thing became complicated when I counted wrongly and thought strlen() was
ok!!! from that point I started to space out.

Sorry about that folks! It was one of those days… > :slight_smile:

JcD



“David Gibbs” <> dagibbs@qnx.com> > wrote in message
news:8uv5lc$eb2$> 1@nntp.qnx.com> …
juan carlos <> jcd@dcs.st-and.ac.uk> > wrote:
Hi,

Is there any function or trick to start a process from another process,
which has not a
string literal (<const char *>) as the parameter for the file name that
contains the process to execute???

I think you misunderstand the meaning of the <const char *> for the
parameter – that doesn’t mean the parameter has to be a constant string.
That means that the function will not change the string, that is, that
the code inside the function must treat that string as a constant.

You can easily do something like:

char buffer[512];

sprintf(buffer, “%s%d”, progname, prog_instance);
spawn*(…, buffer, … );

-David

Well David, you’re right! but you know I’m here in Scotland, thus we drive
on the left side… so at times I drive/type in the wrong lane / \ :slight_smile:


“David Gibbs” <dagibbs@qnx.com> wrote in message
news:8v3vn7$a0s$1@nntp.qnx.com

juan carlos <> jcd@dcs.st-and.ac.uk> > wrote:
Hi,
the problem was just a no visible character on the screen, a fuc…’/n’
that came at the end of a string that my program sucks from a common
buffer
in the network (nobody told me about that ‘/n’!!) and then it was
concatenated at the end of Cell!! i.e.

Are you sure it wasn’t a ‘\n’ – that is a newline character? Anyway,
glad you figured things out.

-David

Cell ="Hello "
Buffer=“World’/n’”
Cell+Buffer=“Hello World/n”

So you see
Hello World

… and everything seems to be ok, till you do a strlen(Buffer) and
oopsss!!!

The thing became complicated when I counted wrongly and thought strlen()
was
ok!!! from that point I started to space out.

Sorry about that folks! It was one of those days… > :slight_smile:

JcD




“David Gibbs” <> dagibbs@qnx.com> > wrote in message
news:8uv5lc$eb2$> 1@nntp.qnx.com> …
juan carlos <> jcd@dcs.st-and.ac.uk> > wrote:
Hi,

Is there any function or trick to start a process from another
process,
which has not a
string literal (<const char *>) as the parameter for the file name
that
contains the process to execute???

I think you misunderstand the meaning of the <const char *> for the
parameter – that doesn’t mean the parameter has to be a constant
string.
That means that the function will not change the string, that is, that
the code inside the function must treat that string as a constant.

You can easily do something like:

char buffer[512];

sprintf(buffer, “%s%d”, progname, prog_instance);
spawn*(…, buffer, … );

-David

Mmmmm… Single malt…


“juan carlos” <jcd@dcs.st-and.ac.uk> wrote in message
news:8v95u1$8m6$1@inn.qnx.com
| Well David, you’re right! but you know I’m here in Scotland, thus we drive
| on the left side… so at times I drive/type in the wrong lane / \ :slight_smile:
|
|
| “David Gibbs” <dagibbs@qnx.com> wrote in message
| news:8v3vn7$a0s$1@nntp.qnx.com
| > juan carlos <jcd@dcs.st-and.ac.uk> wrote:
| > > Hi,
| > > the problem was just a no visible character on the screen, a fuc…’/n’
| > > that came at the end of a string that my program sucks from a common
| buffer
| > > in the network (nobody told me about that ‘/n’!!) and then it was
| > > concatenated at the end of Cell!! i.e.
| >
| > Are you sure it wasn’t a ‘\n’ – that is a newline character? Anyway,
| > glad you figured things out.
| >
| > -David
| >
| > > Cell ="Hello "
| > > Buffer=“World’/n’”
| > > Cell+Buffer=“Hello World/n”
| >
| > > So you see
| > > Hello World
| >
| > > … and everything seems to be ok, till you do a strlen(Buffer) and
| > > oopsss!!!
| >
| > > The thing became complicated when I counted wrongly and thought strlen()
| was
| > > ok!!! from that point I started to space out.
| >
| > > Sorry about that folks! It was one of those days… :slight_smile:
| >
| > > JcD
| >
| >
| >
| >
| > > “David Gibbs” <dagibbs@qnx.com> wrote in message
| > > news:8uv5lc$eb2$1@nntp.qnx.com
| > >> juan carlos <jcd@dcs.st-and.ac.uk> wrote:
| > >> > Hi,
| > >>
| > >> > Is there any function or trick to start a process from another
| process,
| > >> > which has not a
| > >> > string literal (<const char *>) as the parameter for the file name
| that
| > >> > contains the process to execute???
| > >>
| > >> I think you misunderstand the meaning of the <const char > for the
| > >> parameter – that doesn’t mean the parameter has to be a constant
| string.
| > >> That means that the function will not change the string, that is, that
| > >> the code inside the function must treat that string as a constant.
| > >>
| > >> You can easily do something like:
| > >>
| > >> char buffer[512];
| > >>
| > >> sprintf(buffer, “%s%d”, progname, prog_instance);
| > >> spawn
(…, buffer, … );
| > >>
| > >> -David
| >
| >
|
|