Your problem is that you are passing two options two the script rather than the four that getopt expects. That is, -i infile.txt
is treated as one option, not, as getopt expects, the two options -i
and infile.txt
, and the same thing is happening to -o outfile.txt
. You can fix this by replacing the line:
String[] cmdArray = new String[] { python.toString(), script.toString(), "-i infile.txt", "-o outfile.txt" };
with this line:
String[] cmdArray = new String[] { python.toString(), script.toString(), "-i", "infile.txt", "-o", "outfile.txt" };
Notice that now -i
and infile.txt
are now separate array elements, as are -o
and -outfile.txt
.