WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: STDOUT / STDERR  (Read 2252 times)

Offline Daniel

  • Full Member
  • ***
  • Posts: 166
STDOUT / STDERR
« on: February 07, 2011, 11:59:49 AM »
Hi,

With my application, I'am waiting for an USB device.

For that, i do "ls /dev/sdb1"

with my application run under ubuntu 10.04, an error goes to stderr.
with tcl, the error goes to stdout.

I've test : 'ls /dev/sdb2 1>t1 2>t2'
the error result is in t1 (t2 for ubuntu).

what have i to do to change that and to have the same as ubuntu in order to do both without change?

thanks
Daniel.

[EDIT]
or an other way of doing the same in both cases?  :)


« Last Edit: February 07, 2011, 12:02:10 PM by Daniel »

Offline danielibarnes

  • Hero Member
  • *****
  • Posts: 548
Re: STDOUT / STDERR
« Reply #1 on: February 07, 2011, 02:54:17 PM »
To redirect both stdout and stderr to the same output, use "&>" as in:
ls /dev/sdb1 &>t

However, if you are waiting on a usb device there may be better options depending on your use:

1) During bootup, you can use the waitusb bootcode and include the device, label or UUID of a USB device (if it is always the same):
waitusb=7:DEVICE=/dev/sdb1
waitusb=7:UUID=xxxx
waitusb=7:LABEL="label"

2) Use blkid to check for the presence of the device instead of ls:
blkid -lt DEVICE=/dev/sdb1 && echo Success
or
blkid -lt DEVICE=/dev/sdb1 || echo Failed
or
while ! blkid -lt DEVICE=/dev/sdb1; do sleep 0.25; done

Offline Daniel

  • Full Member
  • ***
  • Posts: 166
Re: STDOUT / STDERR
« Reply #2 on: February 08, 2011, 11:43:04 AM »
Thanks!

Now, i'm using blkid to see if an usb device is present.

blkid -o device
with filtering the response.
:)

Daniel.

PS: there is a difference between tcl and ubuntu.
Perhaps because in tcl, stderr is redirected on stdout ? ??? ??? ???

Offline danielibarnes

  • Hero Member
  • *****
  • Posts: 548
Re: STDOUT / STDERR
« Reply #3 on: February 08, 2011, 01:26:16 PM »
Quote
PS: there is a difference between tcl and ubuntu.

It may be the shell. Ash and bash use the syntax I gave you. I realize you may not need it now, but you can also redirect like this:

ls -l /dev/sdb1 2>&1 >t

Offline Daniel

  • Full Member
  • ***
  • Posts: 166
Re: STDOUT / STDERR
« Reply #4 on: February 09, 2011, 03:00:07 AM »
Thanks!

What i wanted is to have the same for both ubuntu and tcl.

error -> stderr.

With "blkid", i modify the program for both!
:)
Daniel.