obtain user input from CreateProcess with CREATE_NEW_CONSOLE

I do this:

if (!CreateProcessA(NULL, lArgs, NULL, NULL, FALSE,
    CREATE_NEW_CONSOLE, NULL, NULL, &StartupInfo, &ProcessInfo))
    return GetLastError();

But I don't know how to obtain the input from the console.

Am I oblige to write a file for it ?

EDIT 1: there is no trouble, it works (and the code is both C and C++). this create a console, what I am looking for is: How do I obtain in this scope the user input from this new console ? lArgs contains the parameters/command line I pass to this new console.

EDIT 2: (I don't have any trouble. it works fine.) The child process is a console and I am trying to obtain the user input in the console (child process) to the parent process.

EDIT 3: The child process is just a console as in "CREATE_NEW_CONSOLE". The command line is given to the console with lArgs. This command runs a program of which the result is displayed in this new console. If I use _popen (I don't want to) instead of createprocess this displayed result is returned by _popen, but with createprocess, it just seems to be lost.


OK; it would seem that the problem here is that you're hopelessly confused about the terminology.

The word "console" as in CREATE_NEW_CONSOLE does not mean what you think it means. No process is a console; a console is something a process has. Specifically, a console is the text-based window that command line applications (including but not limited to the command interpreter) use for input and output. The CREATE_NEW_CONSOLE flag says to the system "create a new console window for this child process instead of using mine".

What you're trying to do, apparently, is to to launch a new command interpreter. You do not need the CREATE_NEW_CONSOLE flag to do that.

(Note that if the program you actually want to run is an executable, you don't need the command interpreter at all, regardless of whether you want the program to have a separate console or not. Any executable, including a command-line executable, can run independently, it does not need to have the command interpreter as a parent. Generally speaking you would launch a new command interpreter as a child process only if you want to run a batch file; for the sake of argument, I'll assume that's what you're doing.)

Also, the phrase "user input" means just that - the input that the user provides to the program. In this context, the stuff a person types on the keyboard. The child process, whether that's the command interpreter or another program, is not the user, and in your case it is generating output rather than accepting input. So what you're wanting is called the child process output, or in this case you could alternatively describe it as the command interpreter output.

So, the question you meant to ask:

I am launching a command interpreter with CreateProcess and I want the output to go to my console rather than to the new console. How can I do this?

And the answer is: this is the default behaviour. Take away the CREATE_NEW_CONSOLE flag, which explicitly tells Windows to do exactly what you don't want it to, and it will behave in the way you want.

You could use _popen instead. It would return the command line input from the user.

Need Your Help

Open Layers Hover event not working


I can't get the hover event to register properly, I don't know why. I have done some so far unfruitful we research, any ideas??? The first line works great, but the second does not.

background app in iOS that detects incoming phone calls

iphone objective-c xcode ios4

I need to write a background application in iOS which listens to incoming phone calls on the iPhone.