Run a CMD command from inside atom using path of FOLDER containing the file I am editing


Hello guys!

I am an Atom beginner and I am no programmer, however I do have to work with code as a sound designer and Atom was suggested by friends because of it’s unlimited openness.

Currently after I am done writing a config file, I right click the folder containing the config and by using an added shell-command I do this:

"C:\Path_To_Tool\makePBO.exe" -L -B -G "%1" "E:\Downloads\TargetPath"

I managed to come up with this “line of code” with lots of help of a friend.

So the first half is the path to a tool that packs up folders into packages.
The “%1” is the folder path so the tool knows what folder to process.
The 2nd path is for the tool to know where to put the final data.

I would like to execute above command from INSIDE Atom. I need to learn how to first execute code from inside Atom (I am really a noob) and how to pass along the “path of the folder which contains the file I am editing” to that code as a “%1”.

So in an ideal world I would hit a keycommand in Atom and the makePBO tool would pack up the data, automatically knowing the path of the folder which contains the currently open file.

Is something like this possible and if yes, could someone help me get there?

Thank you very much folks,

have a nice day!


Hello there,
I think what you’re asking is possible indeed, you just need do play around a bit in order to make things work.

What I would suggest you is to use a BufferedProcess to spawn the packaging command from within the Atom Init File.

What happens here is that you create a new command Atom will respond to, and you add it to the init file. Let’s say your command looks like this:

atom.commands.add 'atom-text-editor', 'PackUtils:create-package', ->
  # packaging logic will be implemented here
  # you can use a buffered process to create your package

Whenever you’re in a text editor, you can invoke this command through the Command Palette.
Now, you just need to create a BufferedProcess within your new command.


Bey b3by, thank you for your reply!

Like I said in the OP, I am no programmer and I am using Atom for 1 day. The only thing I understood from your post is that I can add functionality to Atom by editing the init file. Although I don’t know the details I understand the concept. But the BufferedProcess thing is completely beyond me. :frowning: I don’t understand the example in the documentation and have no idea how I can execute a command line in there. :frowning: Sorry.

Maybe you can help me build this? It would be really appreciated mate.


Take a look at process-palette

It allows you to run shell commands from within Atom. You can also use parameters from the environment (like the path of the file being edited) in the command.

In your case you can use:

“C:\Path_To_Tool\makePBO.exe” -L -B -G “{fileDirAbsPath}” “E:\Downloads\TargetPath”

%1 was replaced with {fileDirAbsPath}, which is the path of the folder containing the file being edited.

process-palette has a graphical editor to configure commands with, so you don’t have to work directly with a BufferedProcess.


This is really epic!

Thank you, exactly what I have been looking for! This is really newbie-friendly, wow! :slight_smile: Thanks!



Sure! You’re welcome. I hope the documentation is clear and that you’re able to do with it what you intend. There may be other packages that does similar stuff, but if not and it doesn’t do quite what you need then you can always log a feature request.


Dude I am running my commands with shortcuts, feeling like a pro!!! No more questions! :slight_smile: Thank you so much!


Maybe the only thing:

It would be awesome to be able to run a batch file instead of having to paste the command into the line. Is that at all possible? :slight_smile:



I’m not a Windows user, so I cannot verify this, but try the following.

Let’s say your batch file is called test.bat

Try to run it with the following command:

cmd.exe /c start test.bat


Thank you, works flawlessly for batches but (obviously) not for batches that work with variables like folderPaths etc. I’ll stick to my simple stuff. Thank you so very much mate!


Glad to hear it’s possible to run batch files that way!

You can pass arguments to a batch file, so if you want to experiment a bit more then try the following:

Let’s say, for example, that your test.bat simply receives two arguments and prints them:

echo %1 %2

Your command can then look something like:

cmd.exe /c start test.bat "Hello" "{fileDirAbsPath}"

%1 will then be “Hello” and %2 whatever fileDirAbsPath is.

Once again, I can’t verify this, but in theory it should work. It might be worth a shot :slight_smile:


Passing variables works flawlessly, thank you so much! :slight_smile:


Awesome! :beers:


Install build and git clone this to your packages dir. Let me know how it works for you and I’ll publish the package