Pushkar Posted August 21, 2009 Share Posted August 21, 2009 Hi All,I am a new member here, so first up Greetings to all members and hats off to the creators of this amazing language (I am sure you guys must have heard this an awful lot of times).I was trying to create a child process with redirected I/O using the Windows APIs. I have used anonymous pipes for the I/O redirection. I created two pipes, one for child's STDIN (hereafter referred to as input pipe) and the other for child's STDOUT (hereafter referred to as output pipe). I am not using STDERR. I have used _WinApi_SetHandleInformation to ensure that the child does not inherit write handle of input pipe and the read handle of output pipe.Once the child process gets created, I can get the child to write something to its STDOUT and read off of it from the parent side. This works like a charm.However, if I write something to the input pipe from parent and try reading it from the child using _WinApi_ReadFile, the function fails immediately with INVALID_HANDLE_VALUE.GetLastErrorMessage shows the corresponding error message - handle is invalid. I have verified that WriteFile from parent succeeds in writing the data.I have also noticed that GetLastErrorMessage returns "Specified procedure could not be found" after _WinApi_CreateProcess, which doesn't make sense to me since the child process does get created.I have tried everything I could think of. Google hasn't been able to help much.Please see attached for the parent and child side codes.Any help here will be greatly appreciated.Thanks in advance!Redirected IO.zip Link to comment Share on other sites More sharing options...
autoitter Posted August 22, 2009 Share Posted August 22, 2009 Why not use the built-in functions StdoutRead, StderrRead and StdinWrite? Link to comment Share on other sites More sharing options...
Yashied Posted August 22, 2009 Share Posted August 22, 2009 (edited) And why do not use ShellExecute() instead _WinApi_CreateProcess(). Edited August 22, 2009 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Pushkar Posted August 23, 2009 Author Share Posted August 23, 2009 Well yeah, I have those options, but I really want to do this via Windows APIs, for one this is a learning process for me. Secondly, the code is only a part of the entire thing (which will follow once this gets sorted out) and I'll need to take care of inheritance of handles. Third, I would have implemented the solution that you suggested (maybe I will have to since this is not getting resolved), I want to find out what is wrong with the code or why is it not working just for the sake of satisfying my curiosity. Just getting something to work or abandon something not working is really not what I do. I need a reason for it not working or working. I hope you understand what I am trying to say. Thanks! Link to comment Share on other sites More sharing options...
Pushkar Posted August 25, 2009 Author Share Posted August 25, 2009 Hi...There has been a small goof up with the code. Please locate this line: _WinAPI_SetHandleInformation ($hndInputPipe_Rd, $HANDLE_FLAG_INHERIT, 0). This should be corrected to: _WinAPI_SetHandleInformation ($hndInputPipe_Wr, $HANDLE_FLAG_INHERIT, 0) as its the write handle of input pipe I don't want the child to inherit. Rest is the same. Thanks !! Link to comment Share on other sites More sharing options...
Pushkar Posted August 28, 2009 Author Share Posted August 28, 2009 Can somebody help with this? Link to comment Share on other sites More sharing options...
danls Posted January 16, 2012 Share Posted January 16, 2012 Any resolution to this issue? I am having a problem with WinAPI processes, but for me the process is exiting before it should. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now