Build and run with arguments in Sublime Text 2

20,191

Solution 1

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

Solution 2

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.

Solution 3

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

import os
os.system("python filename.py some args")
Share:
20,191
Alexandre Huot
Author by

Alexandre Huot

Updated on November 01, 2020

Comments

  • Alexandre Huot
    Alexandre Huot over 3 years

    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.