How does Atom handle sub-shell commands?


I want to be able to pass a buffer of Markdown text to an external application, like on OS X. In Sublime Text I can achieve this with the following command:

open -a Marked {current_file}

How can I get a similar effect with Atom?


You can do the same thing with Atom. If you don’t care about the output you can use Node.js’s spawn method or you can use Atom’s BufferedProcess if you do. If you don’t want to force a save, you might have to do a little bit to save the contents in a temp file, but that shouldn’t be too hard.


Thanks @leedohm. I think the spawn method is the right one for what I want to accomplish I’m not really a Node person. Is there plugin source you could point me to that does something similar? Namely, spawn a command that opens the file in the current buffer for reading. Thanks!


Well, if all you want to do is open a file in Atom, then all you need is If you specifically want to open the contents of a file in the current buffer, overwriting the contents of whatever you might have in that buffer … then you can use Node’s fs.readFileSync() to read the contents of a file and then simply use the Editor methods to overwrite the contents of the current buffer.

No spawning of processes necessary …


That’s useful information, @leedohm so thanks. However, it’s not in the direction I need. Here’s what I want to do:

  • I need to determine the pathname of the current buffer in the local filesystem. It doesn’t matter to me if the buffer has been saved or not—that’s the user’s responsibility.
  • Armed with the pathname of the current buffer, I want to spawn a command that takes that pathname as a parameter.

I don’t care about output or exit status, so spawn will do just fine. Basically, I just need to know where Atom sticks the current buffer and spawn a command with that pathname. For the record, the external command will open the file as read-only, so I’m not worried about the buffer being modified out of band.

Thanks in advance for any insight you can give me.


I’m pretty sure it’s just editor.path which may be a passthrough to buffer.path but I’ve been on the road for about twelve hours today and I’m getting ready to slide into bed. I’ll look it up in the morning if that hint doesn’t get you the rest of the way there.