• Post Reply Bookmark Topic Watch Topic
  • New Topic

Controlling cmd from java  RSS feed

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, ive been trying so many things to enter several commands from my java program but i havent been succesful. I hope someone can help...
This is what i want to do from java which i can do it manually from cmd.

1. open cmd
2. cd \123\ABC\edf\456
3. (run this command) dsm.cmd –f CREATE –b DSKfromjava –V bb9server.bbdn.local

***dsm.cmd takes this parameters: –f CREATE –b DSKfromjava –V bb9server.bbdn.local

now i can get in java to step 2 with no problem in jave using something like this..


However, I havent find a way to keep inputing commands from java to dos command... am I trying something impossible? PLEASE HELP!!

 
Ranch Hand
Posts: 802
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may get help from this
 
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carefully read the JavaDocs for java.lang.Process

Bill
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

you can try like
Process proc = Runtime.getRuntime().exec(cmdArgs, null, workingDir);

process.getInputStream(); // simple message handling
process.getErrorStream(); // error handing

process.waitFor(); // wait until the process is not finished

Hope this helps.

Regards
Kulbir
 
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't go anywhere near Process until you have read the link Ninad Kulkarni posted.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
write all the stuff in a bat file using java and call that file ex: runtime.exec("file.bat");
 
Eduardo Ponce de Leon
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i got the bat to work with all the parameter it takes... now I want to get the input that the bat produces so that i can see it in my console...
This is what I have...


Whenever i run this... this is what i get on my java console
java.io.BufferedInputStream@f62373
java.io.FileInputStream@19189e1

but the input i should be getting is something like this...

Data Source Key Description
--------------- -----------
INTERNAL Internal data source used for associating records that are created for use by the Bb system.

SYSTEM System data source used for associating records that are created via web browser.

REPLICATED Replicated data source used for root administrator.
LMS_INTEGRATION LMS Integration data source used for associating records that are created during integration sync operations.

Test_DSK
VERANO1 Descripcion del Datasource
VERANO2 Descripcion del Datasource
VERANO3
VERANO4
FROMJAVA
FROMJAVA2
FROMJAVA3
FROMJAVA4
FROMJAVA5

 
Sheriff
Posts: 22846
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you have to actually read from the input stream. Just printing the value of its toString() method isn't going to do anything.

And let me be the third person to tell you that you must read this article. It's obvious that you haven't done that yet.
 
Eduardo Ponce de Leon
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
let me tell you all 3 that youre article is completely useless...it was as simple as this...




Thank you to Kulbir Java and amrish sharma with actually gave options!!
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if the process writes to stdErr there is a good chance it will hang mysteriously.

Bill
 
Eduardo Ponce de Leon
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The steamgobbler from the article you mentioned seems perfectly fine, however i was never able to get an error stating that the class already exists, no matter if i had created or not! so i had to figure other things.. no matter what the .cmd will output something and ive added.. HOpefully that would solve it.

int exitVal = proc.waitFor();
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!