Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Switch directories and then fire command with parameters

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey all I am trying to change directories and then run my command with parameters.


It runs without errors but outputs nothing. However, this is what shows up after it finishes:

<terminated, exit value: 0>C:\Local Apps\IBM\SDP\jdk\bin\javaw.exe (Jul 22, 2019, 11:21:37 AM)


The expected output should be:



So am I doing this correctly?
 
Saloon Keeper
Posts: 2656
333
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest that you take what you are passing to exec, and try running in a command Window and see if it provides the expected results.

What you are passing looks like this:
   cmd /c "\Local// Apps\IBM\SDP\scmtools\eclipse"scm help

What you want to pass should probably look like this:
   cmd /c "C:\Local Apps\IBM\SDP\scmtools\eclipse\scm" help
 
Marshal
Posts: 65038
247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does the slash (//) mean before the space after Local? Why is it // rather than \\?

Why are you using that dreadful read() method?
 
David Go
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The // between Local Apps is said to take care of the space between the names. I was using something and it kept saying "cant find dir \Local"
 
Ron McLeod
Saloon Keeper
Posts: 2656
333
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you wrap the path in quotes (which you are already doing), then there is no need to escape the spaces.
 
Sheriff
Posts: 21775
103
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not use ProcessBuilder? It is a lot user-friendlier than Runtime.exec. For instance:

And you can also easily specify the directory to run in (note: Runtime.exec is overloaded to take a File argument for the same purpose):


From the way you're reading from the process' InputStream I can see you haven't read When Runtime.exec() won't. The articles is old, but the warnings are still valid. There is one update they should make - you can redirect the error stream to the output stream:

Now you don't have to worry about the stream gobbling threads anymore, you can just read from the InputStream because it also contains the error output.
 
Does this tiny ad smell okay to you?
Java Code Review and Psychology
https://coderanch.com/t/714798/java/Java-Code-Review-Psychology
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!