Hi all,
The shell program compiles under Linux fine, with -g so that any errors
would be displayed, but when the code is executed, the process ends
without error.
Here is the call:
strcpy( path, (const char *)tokens[0].c_str() );
path was declared with: char* path; but never initialized to
anything.
tokens[] is an STL vector of strings (not c-strings).
at the point of the call, tokens[0] = "/bin/ls"
So below is the context in which the call occurs. The child process is
spawned, the output looks like
"esh% /bin/ls
Input was a user command, about to fork
In the child process, building the args[]
about to build path
path is libc.so.6
esh%"
when it should continue
"just filled path with tokens[0]"
but it doesn't.
Context:
else if ( pid == 0) { // child process
cout << "In the child process, building the args[]" << endl;
cout << "about to build path" << endl;
cout << "tokens[0] is " << tokens[0].c_str() << endl;
char* path; // path for execl
cout << "path is " << path << endl;
// build path
// everything works fine up til here
strcpy( path, (const char *)tokens[0].c_str() );
// this line of code is never executed because the previous one
caused process
// to die
cout << "just filled path with tokens[0]: " << path << endl;
For any help, I would greatly appreciate it.
Thanks,
Dan