0

I have an application that takes a few command line parameters, then prints some text to the terminal, then starts writing data to a file. It has a parameter I can use to define the file name to write to (like -o some-file-name.bin).

I would like to process that data (live) using another application, so I tried making the program output its data to stdout by specifying -o - and piping the output to another tool. However, unfortunately, that program isn't smart enough to notice that it is writing to stdout and that it should stop writing human-readable text to stdout (as that messes up the binary data).

So, usually, the tool would write text to stdout (which I don't care about) and data to a file. I would like to ignore all the text written to stdout and instead have it write the data to stdout so I can pipe it into another tool. However when I run it with -o -, it writes both the (binary) data and the useless text into stdout, ruining the data.

I tried -o >( my_other_tool ) instead of a pipe, but that resulted in Couldn't open output: /dev/fd/63: /dev/fd/63: No such file or directory.

Is there another way - other than recompiling the tool and removing all the useless printf calls - to ignore the original stdout and send the data it would write to a file to stdout instead?

EDIT: In case it is helpful, I am talking about nsntrace.

  • 1
    If the program makes use of -f - there should also be something like -q for "quiet", given it's not done by default. Have you checked that? – Tomasz Jun 21 at 13:54
  • I did check that, and no, there is no option to silence the program. I need to do that externally (or modify the source and recompile it, which I don't really like doing). – Florian Bach Jun 21 at 14:01
  • 2
    I'm not sure I understand what you're about but try program -f /dev/fd/3 3>&1 >/dev/null | ... – mosvy Jun 21 at 14:01
  • Unfortunately, that also silences the binary data the program is supposed to output (to fd 3). – Florian Bach Jun 21 at 14:03
  • 2
    Yes, it works. Provided, of course, that you're using the -o, not the -f option: src/nsntrace -o /dev/fd/3 wget www.google.com 3>&1 >/dev/null | .... I supposed you assumed that it cannot work. This is really annoying. – mosvy Jun 21 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.