0

I have a node project where I output a filename to stdout in the terminal with process.stdout.write(filename + '\n');. How can I pipe this output to the open command or some other command to open the file (an image in this case) with the default image viewer?

3
  • node some_node_file.js | open -f As far as I know open waits filename as an argument, so it's just bash issue. Commented Jan 26, 2016 at 18:51
  • Piping into open -f simply opens the output text (a.k.a. the file name) in the default text editor. It doesn't open the image file with the default image viewer. Commented Jan 26, 2016 at 19:35
  • If you want it to open a specific application, you need to pass -a <appname>. I guess you need Preview for images. Commented Jan 26, 2016 at 22:07

1 Answer 1

1

As Mark Setchell points out in the comments, you will need to pass -a <appname> to open the file with a specific application.
However, you will need to pipe the file to stdout instead of just the filename, fore example like this:

var fs = require('fs');

fs.createReadStream("./test.jpg").pipe(process.stdout);

and then of yourse node yourNodeFile.js | open -f -a Preview.app

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.