I am trying to execute a linux command from my java class using the method exec() from the Runtime class in this way:
//////////////////////////////
public static String xxUtilInfoFile (String sPath , String sFileName) throws Exception {
Runtime r = null;
Process p = null;
String line_value="";
String output_data="";
/*execute the process*/
r = Runtime.getRuntime();
p = r.exec("file -bi " + sPath + sFileName);
p.waitFor();
/*Return the standard error output*/
BufferedReader in=new BufferedReader(new InputStreamReader(p.getInputStream()));
output_data = in.readLine();
return output_data;
}
/////////////////////////////////////
The linux command I want to use is 'file -bi fileName' and it runs well except in the case the fileName has blanks inside, and that is the point.
I've already try to use double quotes and backSlash (/) because this methods runs in the linux bash console, but it doesn't run if i pass it as an argument of exec method.
¿Could anyone to help me to resolve this issue?
Thanks in advance.
executing linux commands from java
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
18 October 2019, 14:28
try stackoverflow
0