PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > How to catch STDIO STREAM?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
How to catch STDIO STREAM?

Réponse
 
LinkBack Outils de la discussion
Vieux 26/05/2008, 22h52   #1
Cheyne Li
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut How to catch STDIO STREAM?

Hi, there

How can I capture a error massage from the STD IO?
For instance, I have a program call foo.exe and i run the program
/foo.exe

Then the program prints out some error messages.

How can I write a script that capture the errors and save then into a
file?
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 26/05/2008, 22h58   #2
Axel Etzold
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to catch STDIO STREAM?


-------- Original-Nachricht --------
> Datum: Tue, 27 May 2008 06:52:55 +0900
> Von: Cheyne Li <happy.go.lucky.clr@gmail.com>
> An: ruby-talk@ruby-lang.org
> Betreff: How to catch STDIO STREAM?


> Hi, there
>
> How can I capture a error massage from the STD IO?
> For instance, I have a program call foo.exe and i run the program
> ./foo.exe
>
> Then the program prints out some error messages.
>
> How can I write a script that capture the errors and save then into a
> file?
> --
> Posted via http://www.ruby-forum.com/.


Dear Cheyne,

have a look at this:

http://www.ruby-doc.org/stdlib/libdo...doc/index.html

Best regards,

Axel
--
GMX startet ShortView.de. Hier findest Du Leute mit Deinen Interessen!
Jetzt dabei sein: http://www.shortview.de/?mc=sv_ext_mf@gmx

  Réponse avec citation
Vieux 26/05/2008, 23h21   #3
Cheyne Li
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to catch STDIO STREAM?

Thank you for your information. I tried, but it only give me result like
#<IO:0xf60e8>

So, is there a way to convert it into string?


Axel Etzold wrote:
> -------- Original-Nachricht --------
>> Datum: Tue, 27 May 2008 06:52:55 +0900
>> Von: Cheyne Li <happy.go.lucky.clr@gmail.com>
>> An: ruby-talk@ruby-lang.org
>> Betreff: How to catch STDIO STREAM?

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

>
> Dear Cheyne,
>
> have a look at this:
>
> http://www.ruby-doc.org/stdlib/libdo...doc/index.html
>
> Best regards,
>
> Axel


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

  Réponse avec citation
Vieux 26/05/2008, 23h37   #4
Axel Etzold
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to catch STDIO STREAM?


-------- Original-Nachricht --------
> Datum: Tue, 27 May 2008 07:21:55 +0900
> Von: Cheyne Li <happy.go.lucky.clr@gmail.com>
> An: ruby-talk@ruby-lang.org
> Betreff: Re: How to catch STDIO STREAM?


> Thank you for your information. I tried, but it only give me result like
> #<IO:0xf60e8>
>
> So, is there a way to convert it into string?
>




Dear Cheyne,

yes, there is. Use readlines, like this:


-------------------------------
require "open3"

filenames=%w[file1 file2 file3]
inp,out,err=Open3.popen3("xargs","ls","-l")

filenames.each{|f| inp.puts f}
inp.close

output=out.readlines
errout=err.readlines

puts "sent #{filenames.size} lines of input"
puts "got back #{output.size} lines of output"
puts "these were the errors, if any:"
puts errout
-----------------------------------

Best regards,

Axel






>
> Axel Etzold wrote:
> > -------- Original-Nachricht --------
> >> Datum: Tue, 27 May 2008 06:52:55 +0900
> >> Von: Cheyne Li <happy.go.lucky.clr@gmail.com>
> >> An: ruby-talk@ruby-lang.org
> >> Betreff: How to catch STDIO STREAM?

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

> >
> > Dear Cheyne,
> >
> > have a look at this:
> >
> > http://www.ruby-doc.org/stdlib/libdo...doc/index.html
> >
> > Best regards,
> >
> > Axel

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


--
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger

  Réponse avec citation
Vieux 27/05/2008, 07h44   #5
Robert Klemme
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to catch STDIO STREAM?

On 26.05.2008 23:52, Cheyne Li wrote:
> How can I capture a error massage from the STD IO?
> For instance, I have a program call foo.exe and i run the program
> /foo.exe
>
> Then the program prints out some error messages.
>
> How can I write a script that capture the errors and save then into a
> file?


You do not need Ruby for that. At an arbitrary shell prompt:

foo.exe > errors.txt

Kind regards

robert
  Réponse avec citation
Vieux 27/05/2008, 15h23   #6
Sebastian Hungerecker
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to catch STDIO STREAM?

Robert Klemme wrote:
> foo.exe > errors.txt


I'm sorry, I don't know Windows that well, but wouldn't that redirect stdout
and not stderr? Or maybe it would redirect both, but what I think the OP
wants is to just redirect the errors while still printing the normal messages
to the screen.


--
NP: Depeche Mode - Useless
Jabber: sepp2k@jabber.org
ICQ: 205544826

  Réponse avec citation
Vieux 27/05/2008, 16h42   #7
Robert Klemme
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to catch STDIO STREAM?

On 27.05.2008 16:23, Sebastian Hungerecker wrote:
> Robert Klemme wrote:
>> foo.exe > errors.txt

>
> I'm sorry, I don't know Windows that well, but wouldn't that redirect stdout
> and not stderr?


Correct.

> Or maybe it would redirect both, but what I think the OP
> wants is to just redirect the errors while still printing the normal messages
> to the screen.


He did not mention explicitly which stream he wanted to redirect that's
why I presented this solution. Of course, you can as well redirect
stderr on Windows.

Kind regards

robert
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 08h33.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,16306 seconds with 15 queries