Question about Runner functionality


#1

I’m using the Runner functionality the Java and it works fine, but I’d like to somehow be able to enter command line arguments before the code is run. Is there a way to prompt the user for command line input?.Thanks!


#2

I’m assuming you have something that looks like:

{
"script": [
    "ROOT=`pwd`",
    "printf \"\\033[01;34mCompiling all files in\\033[00m \\033[01;31m$ROOT\\033[00m\n\"",
    "OUT_DIR=\"$([ -f .bin ] && rm -r .bin; mkdir -p .bin ; echo .bin)\"",
    "FILES=\"$(find . -path './.c9*' -prune -o -print | grep '.*\\.java' | sed 's:^./::g' | tr '\n' ' ')\"",
    "MAIN_CLASS=\"$(echo $file | sed \"s:$ROOT/::g\" | sed 's:.java$::g' | sed 's:/:.:g')\"",
    "COMPILED_FILES=\"$(javac -d $OUT_DIR $FILES)\"",
    "java -classpath \"$OUT_DIR\" \"$MAIN_CLASS\" \"$args\""
],
"env": {},
"info": "\\033[01;34mRunning\\033[00m \\033[01;31m$file_name\\033[00m\n",
"selector": "source.java" 
}

That last line (java -classpath) is where you would put your command line arguments if you want to hard code it, You can see that it uses some variables($name, like $OUT_DIR), and that the $args is there but it is not defined above. If it is not defined it just returns nothing(blank). If you define it, and give it a value, then you will pass in command line arguments. Remember that these things are case sensitive.