Force a program to output to stdout

Silly but handy CLI trick on Linux: Some programs don’t have an option to output to stdout. Gcc comes to mind. In that case the symlink ‘/dev/stdout’ will come in handy: /dev/stdout will be symlinked to stdout for each process.

With this trick you could, for example, run “gcc -S foo.cpp -o /dev/stdout”, to get the assembly listing for foo.cpp.

You probably shouldn’t use this trick on anything other than CLI scripting stuff (keep in mind /dev/stdout might be closed or not accessible for some processes).

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s