Robert Klemme
3/16/2007 9:35:00 PM
On 16.03.2007 21:58, Jan Friedrich wrote:
> Kevin Skrenes schrieb:
>> I need to do this on a Windows machine, so a typical batch file might be
>> constructed like this:
>>
>> echo off
>> cd path\executabledir
>> <command> -S <param> <input> <output>
>>
>> where anything in <> needs to be dynamically populated.
> How about this:
>
> # -- BEGIN OF EXAMPLE
>
> # setting command, param, input, output
> # ...
> cmd = <<END_OF_STRING
> echo off
> cd path\executabledir
> #{command} -S #{param} #{input} #{output}
> END_OF_STRING
>
> system(cmd)
>
> # -- END OF EXAMPLE
You can even combine that:
system <<CMD
echo off
cd path
#{command} -S #{arg}
CMD
And if you need a longer running shell that executes multiple commands
you can use popen:
# IO.popen("bash", "r+") do |io|
IO.popen("cmd", "r+") do |io|
th = Thread.new(io) do |chan|
chan.each {|line| puts line}
end
# io.puts "ls -l"
io.puts "dir"
io.puts "exit"
io.close_write
th.join
end
Kind regards
robert