Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8050395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:04:55+00:00 2026-06-05T07:04:55+00:00

I have a problem at hand which requires me to spawn a command prompt

  • 0

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.

The general logic which I would follow is:

  1. Spawn a different process by using a fork and get a process id
  2. Obtain streams for the process
  3. Write to the input stream of the process and read from the output stream.

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 here. By using that library, I could do step 1 as 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 the win32-process library is based on using processes and threads on windows, I tried to go through the MSDN help for it. While reading the Creation of a Console 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.

Can someone provide me with some guidance on how to proceed with steps 2 and 3?

Also, is there any other way which can be used to solve the problem at hand?

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?

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:04:57+00:00Added an answer on June 5, 2026 at 7:04 am

    Here an example using IO.popen in windows, imo if it works with the stdlib don’t use gems

    IO.popen("other_program", "w+") do |pipe|
      pipe.puts "here, have some input"
      pipe.close_write  # If other_program process doesn't flush its output, you probably need to use this to send an end-of-file, which tells other_program to give us its output. If you don't do this, the program may hang/block, because other_program is waiting for more input.
      output = pipe.read
    end
    
    # You can also use the return value from your block. (exit code stored in $? as usual)
    output = IO.popen("other_program", "w+") do |pipe|
      pipe.puts "here, have some input"
      pipe.close_write
      pipe.read
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying my hand at java and android and have run into a problem which
I have a legacy application at my hand which uses ASP.NET WebForms. My problem
I have design problem, which I would love to get a hand with. I
I have a problem at hand, at first sight it looks easy and it
Problem : I have a hand held device that scans those graphic color barcodes
I have problem with Oracle 9.2 and JMS. I created PL/SQL routine to send
Okay, so here's a problem I'm running into. I have some classes in my
I have some concurrent code which has an intermittent failure and I've reduced the
I'm working on a problem which requires me to use the STL linked list
I have an interesting problem on hand. I have a large model in Erwin

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.