Just popping in
Joined: 2006/12/7 7:47 Last Login
: 2/22 22:11
From Berlin. We're all a bit mad here.
Group:
Registered Users
|
Hello everyone.
I have some code that launches an executable using SystemTags() that looks like this (error checking removed for simplicity):
int32_t exitCode = 0; BPTR stdInRead = Open("Console:", MODE_OLDFILE); BPTR stdOutWrite = Open("PIPE:RADRunner", MODE_NEWFILE); BPTR stdOutRead = Open("PIPE:RADRunner", MODE_OLDFILE);
LONG result = SystemTags("SomeCommand", SYS_Asynch, TRUE, SYS_Input, stdInRead, SYS_Output, stdOutWrite, NP_ExitCode, (ULONG) ExitFunction, NP_ExitData, (ULONG) &exitCode, TAG_DONE);
char *buffer = new char[STDOUT_BUFFER_SIZE]; LONG bytesRead;
do { if ((bytesRead = Read(stdOutWrite, buffer, (STDOUT_BUFFER_SIZE - 1))) > 0) { buffer[bytesRead] = '\0'; printf("%s", buffer); } } while (bytesRead > 0);
You can see that it launches "SomeCommand", passing it a handle to a PIPE: and then reads the output from the command via that pipe, until the command exits and the pipe closes, and Read() returns 0. This works well. But I need to change it to use CreateNewProc() instead:
int32_t exitCode = 0; BPTR stdInRead = Open("Console:", MODE_OLDFILE); BPTR stdOutWrite = Open("PIPE:RADRunner", MODE_NEWFILE); BPTR stdOutRead = Open("PIPE:RADRunner", MODE_OLDFILE);
BPTR segList = LoadSeg("SomeCommand");
struct Process *result = CreateNewProcTags(NP_Seglist, (ULONG) segList, NP_Synchronous, FALSE, NP_Input, stdInRead, NP_Output, stdOutWrite, NP_ExitCode, (ULONG) ExitFunction, NP_ExitData, (ULONG) &exitCode, NP_CloseInput, FALSE, NP_CloseOutput, FALSE, NP_Cli, TRUE, TAG_DONE);
char *buffer = new char[STDOUT_BUFFER_SIZE]; LONG bytesRead;
do { if ((bytesRead = Read(stdOutWrite, buffer, (STDOUT_BUFFER_SIZE - 1))) > 0) { buffer[bytesRead] = '\0'; printf("%s", buffer); } } while (bytesRead > 0);
However, this doesn't work! It gets stuck on the call to Read() and I never get any output from the child command that was launched. I have tried everything but no luck. Am I doing something wrong or does the PIPE: not work with processes created using CreateNewProc()? I have confirmed that the child command is being launched successfully and is executing and exiting.
PS. The reason that I have to switch to CreateNewProc() is that I need to get the exit code from the command being launched. For this I use NP_ExitCode, but this only works with CreateNewProc(). When using it with SystemTags(), it returns the exit code from the *shell* that launches the command, not the command itself.
|