0

I have a shell script which returns the disk usage of a given directory path and Unix user. I would like to execute this command with java system call and below is my code. When I run the command in terminal, it perfectly works, but Runtime.getRuntime().exec(cmd) gives the following error. Any idea what causing this error to happen?

Terminal (works): > usr/bin/status storage --format json "\"path='/a/b/c/d' && User='testuser'

Error: line: Parameter "path='/a/b/c/d' is not defined exit: 234

String s; Process p; try { String cmd = "/usr/bin/status storage --format json \"path='/a/b/c/d' && User='testuser'\""; System.out.println(cmd); //running printed output in terminal works, not in exec() call p = Runtime.getRuntime().exec(cmd); BufferedReader br = new BufferedReader( new InputStreamReader(p.getInputStream())); while ((s = br.readLine()) != null) System.out.println("line: " + s); p.waitFor(); System.out.println ("exit: " + p.exitValue()); p.destroy(); } catch (Exception e) {} 
2

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.