[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

system(...) redirect output to file ?

Rebhan, Gilbert

2/19/2007 9:48:00 AM


Hi,

i use the system method on Windows like that =

Dir.chdir(CVSWORKSPACE) do
system("T:/cvsnt/cvs.exe -d :pserver:testuser@cvs:d:/cvsrepos/test
commit -m 'blabla'")
end

How to redirect the ouptut from a system call to a file ?

Like f.e. C:\>dir > Y:\output.txt in a cmd shell

I need to parse the output from
cvs -update command to get the new files before doing a commit.


Regards, Gilbert



4 Answers

Harry

2/19/2007 10:26:00 AM

0

> How to redirect the ouptut from a system call to a file ?
>
>
>


system("dir > myfile.txt")

Harry
--
http://www.kakueki.com/ruby...

Kalman Noel

2/19/2007 10:38:00 AM

0

Rebhan, Gilbert:
> I need to parse the output from
> cvs -update command to get the new files before doing a commit.

output = `command here`

Note the use of backticks (`), and note that only the command's stdout is
redirected. For more complicated use there is IO.popen. Note furthermore
that ` is a method, which means that (hopefully) all you need to know can
be found via

ri '`'
ri IO.popen

Regards, Kalman

Rebhan, Gilbert

2/19/2007 1:01:00 PM

0


Hi,

-----Original Message-----
From: Kalman Noel [mailto:invalid@gmx.net]
Sent: Monday, February 19, 2007 11:45 AM
To: ruby-talk ML
Subject: Re: system(...) redirect output to file ?

/*
output = `command here`

Note the use of backticks (`), and note that only the command's stdout
is
redirected. For more complicated use there is IO.popen.
*/

until now i redirected the output from cvs update command to a file,
format looks like =

? subfolder1/file4.txt
? subfolder1/file5.txt

and parsed it with =

open($deployserver<<'/cvsout.txt').each { |x|
newfiles<<'.'<<'/'<<x[2..-3]<<' ' }

to get all newfiles in a space separated string for the following
cvs add command

How to do that with the ` backquote method or IO.popen ?

f.e.

Dir.chdir(CVSWORKSPACE)
pipe=IO.popen(".../cvsnt/cvs.exe -d
:pserver:#{ENV["USERNAME"]}@cvsprod:d:/cvsrepos/test update")
??? how do i get the pipe contents into a space separated string ???


Regards, Gilbert







Rebhan, Gilbert

2/19/2007 1:14:00 PM

0


Hi,

did it with =

newfiles=Array.new
Dir.chdir(CVSWORKSPACE)
pipe=IO.popen(".../cvs.exe -d
:pserver:#{ENV["USERNAME"]}@cvsprod:d:/cvsrepos/test update")
p pipe.readlines.each { |x|
newfiles<<'.'<<'/'<<x[2..-2]<<' ' }
puts newfiles.to_s

> ./subfolder1/file4.txt ./subfolder1/file5.txt

Recommended or is there a better way ?


-----Original Message-----
From: Rebhan, Gilbert [mailto:Gilbert.Rebhan@huk-coburg.de]
Sent: Monday, February 19, 2007 2:01 PM
To: ruby-talk ML
Subject: Re: system(...) redirect output to file ?


Hi,

-----Original Message-----
From: Kalman Noel [mailto:invalid@gmx.net]
Sent: Monday, February 19, 2007 11:45 AM
To: ruby-talk ML
Subject: Re: system(...) redirect output to file ?

/*
output = `command here`

Note the use of backticks (`), and note that only the command's stdout
is
redirected. For more complicated use there is IO.popen.
*/

until now i redirected the output from cvs update command to a file,
format looks like =

? subfolder1/file4.txt
? subfolder1/file5.txt

and parsed it with =

open($deployserver<<'/cvsout.txt').each { |x|
newfiles<<'.'<<'/'<<x[2..-3]<<' ' }

to get all newfiles in a space separated string for the following
cvs add command

How to do that with the ` backquote method or IO.popen ?

f.e.

Dir.chdir(CVSWORKSPACE)
pipe=IO.popen(".../cvsnt/cvs.exe -d
:pserver:#{ENV["USERNAME"]}@cvsprod:d:/cvsrepos/test update")
??? how do i get the pipe contents into a space separated string ???


Regards, Gilbert