29

I'm running on MacOS X and I'm using Sublime Text 2 to code.

I've found the command + B option to build and command + shift + B to build and run.

Is it possible to run a program (or script) and pass arguments. Exemple:

myProg arg1 arg2

Note: I'm using multiple languages (C++, Java, Python), so I hope there is a way to set the arguments for each project and not for all build.

Edit

I want to set the parameters for a program call, a little bit like in eclipse where you can set the arguments when you run your program.

nbro
  • 15,395
  • 32
  • 113
  • 196
Alexandre Huot
  • 517
  • 1
  • 5
  • 11

3 Answers3

26

For each project you can create a .sublime-project file with your specific build_system on it:

{
  "folders":
  [{
    "path": "src"
  }],
  "build_systems":
  [{
    "name": "Run with args",
    "cmd": ["python", "$file", "some", "args"]
  }]
}

This way you don't pollute the global Build System menu and won't have to worry about switching build system as you switch projects. This file is also easy to access when you need to change the arguments:

Cmd-Shift-P > Edit Project
OlivierBlanvillain
  • 7,701
  • 4
  • 32
  • 51
  • 1
    buddy if we need to pass dynamic argument every time then what would be the best possible way to get it done....? – Venkatesh Nadar May 03 '14 at 19:56
  • What do you mean by dynamic? You have full access to a shell here, you can store your "dynamic" thing in a file, and read it statically in the sublime build. – OlivierBlanvillain May 03 '14 at 22:38
  • for instance you want to run nodejs npm installer for underscore then you will write command as in "npm install underscore" but next time you want to load express then you will write command as in "npm install express". So my doubt it do we have provision through keyboard to select arg and use it to load node modules same as we have for finding text in file e.g. : select any text in file then ctrl+F. You will find it in find panel. – Venkatesh Nadar May 06 '14 at 12:14
19

InputArgs does precisely what you're looking for. It shows an input dialog every time you run build(ctrl+b) and you can supply it with space separated arguments from within sublime text.

bilalba
  • 783
  • 1
  • 7
  • 22
  • 4
    Does what everyone would expect to do when u do ctrl+shit+b and the dialog opens. It is perfect and handles history of commands supplied (push up). Thank you so much. – m3nda Nov 23 '16 at 02:49
  • I just tried this with a node.js build system, and if I pass a series of parameters separated by spaces, I get them as one big parameter: ie. if I want to simulate `node program.js 1 2 3`, what I get when I enter `1 2 3` in the dialog is a single string `1 2 3` rather than 3 separate string parameters. – Jim Jarrett Apr 04 '17 at 15:02
9

I found a simple solution is create a python file in the same directory:

import os
os.system("python filename.py some args")
nbro
  • 15,395
  • 32
  • 113
  • 196
defool
  • 301
  • 2
  • 4
  • That will be my fallback option (not always under sublime), but need some tweaks like check for os.argv and maybe, using raw_input to ask for many args, then launching with os.execv() instead os.system(). – m3nda Nov 23 '16 at 02:55
  • This is tricky and simple way to run your python script with parameters. This advice had very help me, thanks. – Евгений Па Jan 12 '21 at 08:12