Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
88 user(s) are online (80 user(s) are browsing Forums)

Members: 0
Guests: 88

more...

Support us!

Headlines

 
  Register To Post  

Using PIPE: device with CreateNewProc()
Just popping in
Just popping in


See User information
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.

Go to top
Re: Using PIPE: device with CreateNewProc()
Home away from home
Home away from home


See User information
@Hitman

you need to know if there is x number of bytes in the pipe: buffer before reading.

(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
Go to top
Re: Using PIPE: device with CreateNewProc()
Just popping in
Just popping in


See User information
@LiveForIt

Thanks, I tried that but no luck. In the end, I figured it out - I was using NP_CloseInput, FALSE, and NP_CloseOutput, FALSE and that was causing it to not work! I am guessing that this causes the output to become buffered, so it never gets flushed to the PIPE: and I can't read it.

As soon as I removed these tags it all worked!

Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project