Forum: Ruby How to invoke Windows program with a Ruby command

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
31fdda5f38fc6df4e193cfb7445ddc5a?d=identicon&s=25 RichardOnRails (Guest)
on 2008-10-26 05:25
(Received via mailing list)
Hi,

I've got a command that works in the Command Window of WinXP-Pro/SP3:

F:\Docume~1\AllUse~1\StartM~1\Programs\_Microsoft
\Micros~3\Micros~2.lnk
K:\_Projects\Ruby\_Rails_Apps\PayrollLoader\TestSheet.xls

As I write this post,  the command is written on two lines.  But in
the Command Windows are submitted as a single line with a space
separating the program from the argument.  The command brings up Excel
with the content from the file named in the program's argument.

However, I have not been able to get this to work in Ruby with
system(pgm_name, file_name).  The command does nothing.  It doesn't
crash, as evidenced by the fact that following commands are executed
correctly.

How can I achieve the Command Window result with Ruby 1.8.6?

Thanks in Advance,
Richard
34a7615f38496a5dafbb3e6b721c435e?d=identicon&s=25 Mohit Sindhwani (Guest)
on 2008-10-26 11:14
(Received via mailing list)
RichardOnRails wrote:
> separating the program from the argument.  The command brings up Excel
> with the content from the file named in the program's argument.
>
> However, I have not been able to get this to work in Ruby with
> system(pgm_name, file_name).  The command does nothing.  It doesn't
> crash, as evidenced by the fact that following commands are executed
> correctly.
>
> How can I achieve the Command Window result with Ruby 1.8.6?
>
Took me a while to get this working.

Here's what works:
#make sure that the name of the executable is within quotes
exec_link = "\"c:\\Documents and Settings\\Mohit\\Start Menu\\Quick
Start\\TextPad.lnk\""
#make sure that the document name is within quotes
doc_name = "\"e:\\projects\\tedn01\\extract\\01.extract_styles.rb\""

#launch the 'link' using cmd
my_exec = "cmd /C \"#{exec_link} #{doc_name}\" "

puts my_exec
ret = system(my_exec)
puts ret

Hope this helps.

Cheers,
Mohit.
10/26/2008 | 6:13 PM.
04952a6ee948f345e9c3727850d09a1b?d=identicon&s=25 Dejan Dimic (Guest)
on 2008-10-27 23:36
(Received via mailing list)
On Oct 26, 5:23 am, RichardOnRails
<RichardDummyMailbox58...@uscomputergurus.com> wrote:
> separating the program from the argument.  The command brings up Excel
> Richard
There are many ways to redirect output from your system call.
Take look at: http://www.robvanderwoude.com/redirection.html
Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2008-10-28 09:25
> As I write this post,  the command is written on two lines.  But in
> the Command Windows are submitted as a single line with a space
> separating the program from the argument.  The command brings up Excel
> with the content from the file named in the program's argument.

Might be able to use system("start filename_here")
Good luck.
This topic is locked and can not be replied to.