executing within java a commandline bash command with no output is not executed like -
using code:
private string executecommand(string cmd ) { process p; try { p = runtime.getruntime().exec(cmd); bufferedreader br = new bufferedreader( new inputstreamreader(p.getinputstream())); while ((commandlineoutput = br.readline()) != null){ system.out.println("line:" + commandlineoutput); } p.waitfor(); system.out.println (p.exitvalue()); p.destroy(); } catch (exception e) {} } return commandlineoutput; }
i run following problem: commands generate output executed normal, commands not generating output not executed instance : rm *.jpg not working mkdir is, can not see difference
i quite newbie, googled quite time particular problem never mentioned please me out thanks
when run rm *
on linux, shell interprets , takes care of *
. in java, same shell isn't running, *
isn't being interpreted wildcard.
as pointed here, try extracting target/working directory out of cmd
input , like:
file[] files = new file(<directory>).listfiles(); for(file file : files){ if(file.getabsolutepath().endswith(".jpg")){ //perform delete } }
alternatively, can try (not-tested, since don't have linux box right now):
string[] command = new string[] {"rm", "*.jpg"} p = runtime.getruntime().exec(command);
Comments
Post a Comment