Note that there are some explanatory texts on larger screens.

plurals
  1. POspawning a command prompt in a different process and sending/receiving commands on Windows
    primarykey
    data
    text
    <p>I have a problem at hand which requires me to spawn a command prompt as a different process and send some commands to it and capture/parse the command output. This interaction needs to be in the form of a parent-child process where say all the commands can be put in a ruby file and upon running the ruby file, the commands are sent to the console(command prompt) and output is received from it and processed in the ruby script.</p> <p>The general logic which I would follow is:</p> <ol> <li>Spawn a different process by using a fork and get a process id</li> <li>Obtain streams for the process</li> <li>Write to the input stream of the process and read from the output stream.</li> </ol> <p>The environment which I am using is Windows XP machine with Ruby 1.9.2 installed on it. I downloaded the win32-process library found over <a href="http://win32utils.rubyforge.org/" rel="nofollow">here</a>. By using that library, I could do step 1 as follows</p> <pre><code>require 'win32/process' APP_NAME = "C:\\Windows\\system32\\cmd.exe" process_info = Process.create(:app_name =&gt; APP_NAME, :creation_flags =&gt; Windows::Process::CREATE_NEW_CONSOLE, :process_inherit =&gt; false, :thread_inherit =&gt; true, :cwd =&gt; "C:\\" ) </code></pre> <p>Since the win32-process library is based on using processes and threads on windows, I tried to go through the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms686937%28v=vs.85%29.aspx" rel="nofollow">MSDN</a> help for it. While reading the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms682528%28v=vs.85%29.aspx" rel="nofollow">Creation of a Console</a> article, I found that the GetStdHandle method could be used to get the handles to the input and output streams. But, i could not find this method implemented anywhere in win32-process.</p> <p>Can someone provide me with some guidance on how to proceed with steps 2 and 3?</p> <p>Also, is there any other way which can be used to solve the problem at hand?</p> <p>Also, I would like to learn more about inter-process communication or in general spawning and forking of processes, so can somebody please tell me some good references where I could study them?</p> <p>Thanks in advance </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload