ruby - spawning a command prompt in a different process and sending/receiving commands on Windows -


i have problem @ hand requires me spawn command prompt different process , send commands , capture/parse command output. interaction needs in form of parent-child process commands can put in ruby file , upon running ruby file, commands sent console(command prompt) , output received , processed in ruby script.

the general logic follow is:

  1. spawn different process using fork , process id
  2. obtain streams process
  3. write input stream of process , read output stream.

the environment using windows xp machine ruby 1.9.2 installed on it. downloaded win32-process library found on here. using library, step 1 follows

require 'win32/process'     app_name = "c:\\windows\\system32\\cmd.exe"     process_info = process.create(:app_name => app_name,       :creation_flags => windows::process::create_new_console,       :process_inherit  => false,       :thread_inherit   => true,       :cwd => "c:\\"     ) 

since win32-process library based on using processes , threads on windows, tried go through msdn it. while reading creation of console article, found getstdhandle method used handles input , output streams. but, not find method implemented anywhere in win32-process.

can provide me guidance on how proceed steps 2 , 3?

also, there other way can used solve problem @ hand?

also, learn more inter-process communication or in general spawning , forking of processes, can please tell me references study them?

thanks in advance

here example using io.popen in windows, imo if works stdlib don't use gems

io.popen("other_program", "w+") |pipe|   pipe.puts "here, have input"   pipe.close_write  # if other_program process doesn't flush output, need use send end-of-file, tells other_program give output. if don't this, program may hang/block, because other_program waiting more input.   output = pipe.read end  # can use return value block. (exit code stored in $? usual) output = io.popen("other_program", "w+") |pipe|   pipe.puts "here, have input"   pipe.close_write   pipe.read end 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -