⭑⭑ Use the @file syntax for reading command-line arguments from external text files so you don't have to worry about any of this. ;) ⭑⭑
Argument Parsing:
When calling cmdline tools you first specify the command followed by arguments separated by space. In order to call a command by name without specifying the full path to the executable it needs to be in the PATH (by adding the folder where the executable is %PATH% on Windows, or by symlinking to /usr/bin on Linux/Mac).
e.g. command: filebot, args: [-version]
Code: Select all
filebot -version
Quote Arguments:
If you want to pass an argument that itself contains spaces then you need to quote the value with "x"
command: C:/Program Files/FileBot/filebot.exe:, args: [-rename, D:/New Files]
Code: Select all
"C:/Program Files/FileBot/filebot.exe" -rename "D:/New Files"
e.g. calling rm -r /New Media will remove the folder /New as well as the folder ./Media (path relative to the current working directory)
BAD command: filebot:, args: [-rename, D:/New, C:/Program Files/FileBot/Files]
Code: Select all
filebot -rename D:/New Files
Avoid non-ASCII characters:
Never use non-ASCII characters like “ or ” and note that these characters are not the same as the " standard quotation mark. If a character is not on the keyboard, then it will not have any special meaning on the command-line.
command: echo, args: [Hello World]
Code: Select all
echo "Hello World"
Hello World
Code: Select all
echo “Hello Hello”
“Hello Hello”
Escape Arguments:
If you want to pass an argument that itself contains double-quotes or other special characters that are interpreted by the shell (e.g. * or $ or ! in bash) you may need to further escape these characters with \x.
Escaping arguments correctly is mostly a matter of trial and error. See the following examples to get a feeling for how it works:
How to quote:
Code: Select all
echo "How to \"quote\""
How to "quote"
Code: Select all
echo "How to "quote""
How to quote
Code: Select all
echo "I like $TEST"
I like
Code: Select all
echo "I like \$TEST"
I like $TEST
Code: Select all
echo *.mp4
firefly.101.mp4
Code: Select all
echo \*.mp4
*.mp4
Code: Select all
echo "*.mp4"
*.mp4
Troubleshooting:
If arguments don't get passed as expected, just use trial and error to find the problem. Just break things down step by step and see what works as expected and what does not work as expected.
It helps to see what is actually passed on to the application. Here's a script for that:
Code: Select all
filebot -script fn:sysenv arg1 arg2 ...
Code: Select all
filebot -script fn:sysenv Hello World!
...
args[0] = -script
args[1] = fn:sysenv
args[2] = Hello
args[3] = World!