redirection Windows shell out to variable

View: New views
3 Messages — Rating Filter:   Alert me  

redirection Windows shell out to variable

by born in USSR :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

i want to execute Windows shell commands in my script so that the result
came back in a variable and the new window of a Windows command line
(MS-DOS-session) didn't open.
i write:
> a='dir'
> system(a)
and i see out of 'dir' in window of command line, but i need to get it
into local variable.
And another question:
every time when rubyscript was run command line window is opening, even
if i compile script by exerb. Is it possible to hide window or run
script/rubyexefile without command line window and how if yes?
--
Posted via http://www.ruby-forum.com/.


Re: redirection Windows shell out to variable

by Sven Schott :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You can use the backtick (or backquote) operator ` which is ASCII character
96:

e.g.

a = `dir`

which will give you a string with the stdout of the executed shell. Not that
I would recommend using it with dir mind you. :)


On Thu, Nov 5, 2009 at 1:28 PM, born in USSR <psixxx@...> wrote:

> i want to execute Windows shell commands in my script so that the result
> came back in a variable and the new window of a Windows command line
> (MS-DOS-session) didn't open.
> i write:
> > a='dir'
> > system(a)
> and i see out of 'dir' in window of command line, but i need to get it
> into local variable.
> And another question:
> every time when rubyscript was run command line window is opening, even
> if i compile script by exerb. Is it possible to hide window or run
> script/rubyexefile without command line window and how if yes?
> --
> Posted via http://www.ruby-forum.com/.
>
>

Re: redirection Windows shell out to variable

by Gordon Thiesfeld-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Nov 4, 2009 at 8:28 PM, born in USSR <psixxx@...> wrote:
> And another question:
> every time when rubyscript was run command line window is opening, even
> if i compile script by exerb. Is it possible to hide window or run
> script/rubyexefile without command line window and how if yes?

Run it with rubyw.exe, instead of ruby.exe.

> --
> Posted via http://www.ruby-forum.com/.
>
>