# Re: Running consecutive DOS commands in Ruby

**URL:** <https://www.ruby-forum.com/t/re-running-consecutive-dos-commands-in-ruby/194326>\
**Category:** Ruby\
**Created:** [September 2, 2010, 1:39pm UTC](https://www.ruby-forum.com/t/re-running-consecutive-dos-commands-in-ruby/194326 "2010-09-02T13:39:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Srinidhi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dc4da7/32.png) [@Srinidhi](https://www.ruby-forum.com/u/Srinidhi)\
**Post date:** [September 2, 2010, 1:39pm UTC](https://www.ruby-forum.com/t/re-running-consecutive-dos-commands-in-ruby/194326/1 "2010-09-02T13:39:56Z")

</div>

Hello Everyone,

I have a situation where i have to invoke command line tools like  
putty\_sftp and OpenSSH from ruby script for automation, as out  
application handles sftp uploads through these tools.  
So the problem is i can single DOS command in ruby and store the  
output(using system( ),exec( )), but here were are talking abt  
multiple DOS commands to achieve the goal.  
Also i have to pick up values like user id and password from excel  
file(which i am doing using ruby).I have to know how to pass these  
value to DOS batch file from ruby.

It would be a boon if i can all the DOS commands in my ruby program  
one by one, so it’s easy to parametrize variables without much.  
Please help me in this regard…Thanks

---

<div class="post-metadata">

**Author:** ![Srinidhi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dc4da7/32.png) [@Srinidhi](https://www.ruby-forum.com/u/Srinidhi)\
**Post date:** [September 2, 2010, 2:50pm UTC](https://www.ruby-forum.com/t/re-running-consecutive-dos-commands-in-ruby/194326/2 "2010-09-02T14:50:47Z")

</div>

On Thu, Sep 2, 2010 at 1:35 PM, Srinidhi [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> It would be a boon if i can all the DOS commands in my ruby program  
> one by one, so it’s easy to parametrize variables without much.

What version of DOS are we talking about? Do current versions of Ruby  
run on DOS at all?

In case you happen on a POSIX system you could use IO.popen to start a  
shell (say “/bin/sh”), issue commands and use Ruby’s expect call to  
evaluate output / replies. You could as well create a script in  
memory and feed it to the shell in one go but then you cannot react on  
command outputs or have to generate the decision logic into the  
script.

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![Srinidhi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dc4da7/32.png) [@Srinidhi](https://www.ruby-forum.com/u/Srinidhi)\
**Post date:** [September 2, 2010, 5:41pm UTC](https://www.ruby-forum.com/t/re-running-consecutive-dos-commands-in-ruby/194326/3 "2010-09-02T17:41:11Z")

</div>

On Thursday, September 02, 2010 06:35:33 am Srinidhi wrote:

> I have a situation where i have to invoke command line tools like  
> putty\_sftp and OpenSSH from ruby script for automation, as out  
> application handles sftp uploads through these tools.

Would net-ssh work?

[http://net-ssh.rubyforge.org/](http://net-ssh.rubyforge.org/)

> So the problem is i can single DOS command in ruby

No you can’t.

[http://en.wikipedia.org/wiki/DOS](http://en.wikipedia.org/wiki/DOS)

You probably mean:

[http://en.wikipedia.org/wiki/Command\_Prompt](http://en.wikipedia.org/wiki/Command_Prompt)

> here were are talking abt  
> multiple DOS commands to achieve the goal.

So what’s hard about that?

system(‘command1’, a, b, c)  
system(‘command2’, d, e, f)

> Also i have to pick up values like user id and password from excel  
> file(which i am doing using ruby).I have to know how to pass these  
> value to DOS batch file from ruby.

This sounds like it’s an NT batch question almost as much as a Ruby  
question.  
Since you’re talking about id and password, I’d strongly recommend using  
environment variables. If Windows works the way Unix does here, you  
should be  
able to do something like:

ENV[‘USER\_ID’] = ‘foo’  
ENV[‘PASSWORD’] = ‘bar’

Then, from your batch file, refer to them as:

%USER\_ID%  
%PASSWORD%

This is much more secure than, for example, putting them in the  
commandline.  
But you want to make sure you clear those if you’re going to be running  
other  
commands which don’t need them.

> It would be a boon if i can all the DOS commands in my ruby program  
> one by one,

Sounds like you don’t need to run them in parallel. What’s the problem  
again?
