LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Problem when use getc function before creating a new process with execve() (http://www.linuxquestions.org/questions/linux-newbie-8/problem-when-use-getc-function-before-creating-a-new-process-with-execve-622136/)

anuj_sri 02-18-2008 10:53 PM

Problem when use getc function before creating a new process with execve()
 
Hello,
I am facing a strange problem.
I am using execve() to run a program with new enviornment variables.
before I call execve(), I have to read an input from the user.
When the user types the input, and i read it in my code using gets(); my program works fine, and execve calls other executable as expected.
But if instead of gets() I read user input using getc(), as in
do {
*(pDisp + iCnt++) = getc(stdin);
}while(*(pDisp + (iCnt - 1))!='\n');

then when execve() function is encountered in the code,
execve("./b.out",NULL,c);
It does nothing, it does not call my other executable code.

Any hints ?

blackhole54 02-20-2008 08:29 PM

Quote:

Originally Posted by anuj_sri (Post 3062078)
Any hints ?

How about a WAG?

My C is a bit rusty, but I believe gets() will terminate its output with a null character. Your loop terminates it with a newline. I am wondering if this input is used to set up the environment variables for the execve() call and the lack of a null character is tripping things up.


All times are GMT -5. The time now is 05:15 AM.