Call a script shell from a java program with parametres
I would like to call this shell script:
#!/bin/sh
exiftool -a -u -g1 -j videos/$filename > metadata/$filename1.json;
From a program in java. I try this:
File dir = new File("videos");
String[] children = dir.list();
if (children == null) {
// Either dir does not exist or is not a directory
System.out.print("No existe el directorio\n");
} else {
开发者_如何学运维 for (int i=0; i<children.length; i++) {
// Get filename of file or directory
String filename = children[i];
//Recojo el momento exacto
Process p = Runtime.getRuntime().exec("/home/slosada/workspace/Hola/Metadata.sh "+filename+" "+filename+"");
}
}
But my computer is blocked and I can't do anything. Also, there are no output files.
Maybe, the problem is in how I call the script and how I pass the parametre filename.Any help?
Thanks in advance
You need retrieve the arguments within your shell script:
#!/bin/sh
filename=$1
filename1=$2
exiftool -a -u -g1 -j videos/$filename > metadata/$filename1.json
精彩评论