# Need help with running psexec with array

**URL:** <https://www.ruby-forum.com/t/need-help-with-running-psexec-with-array/204322>\
**Category:** Ruby\
**Created:** [March 9, 2011, 8:38pm UTC](https://www.ruby-forum.com/t/need-help-with-running-psexec-with-array/204322 "2011-03-09T20:38:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [March 9, 2011, 8:38pm UTC](https://www.ruby-forum.com/t/need-help-with-running-psexec-with-array/204322/1 "2011-03-09T20:38:56Z")

</div>

I’m trying to run commands on a remote machine via psexec. The issue  
that I’m having is when grabbing the IP address from the array it wants  
to put everything that follows on a separate line.

uName = “admin”  
pWord = “1234”  
ip = IO.readlines(“ipAddresses.txt”)

ip.each do |host|  
puts “psexec \\#{host} -u #{uName} -p #{pWord} cmd”  
end

the reply is

psexec \127.0.0.1  
-u admin -p 1234 cmd

is there a way to get that output on the same line so that psexec can  
run properly with the system process. Or is there a better way to  
approach this issue?

thanks

---

<div class="post-metadata">

**Author:** ![gibbons](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/7ab992/32.png) [@gibbons](https://www.ruby-forum.com/u/gibbons)\
**Post date:** [March 10, 2011, 1:04am UTC](https://www.ruby-forum.com/t/need-help-with-running-psexec-with-array/204322/2 "2011-03-10T01:04:15Z")

</div>

I did some more testing and I found the issue. It is with how the file  
is being placed in the ip array.

How would you import each line of the ipAddress.txt file into a  
different object in the array?

---

<div class="post-metadata">

**Author:** ![gibbons](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/7ab992/32.png) [@gibbons](https://www.ruby-forum.com/u/gibbons)\
**Post date:** [March 12, 2011, 12:53am UTC](https://www.ruby-forum.com/t/need-help-with-running-psexec-with-array/204322/3 "2011-03-12T00:53:17Z")

</div>

Christopher G. wrote in post #986599:

> I did some more testing and I found the issue.  
> It is with how the file is being placed in the ip array.

Yes, you need to run String#chomp() on each item in the Array:

puts “psexec #{host.chomp} …”

That removes the newline character at the end of each item.
