• Post Reply Bookmark Topic Watch Topic
  • New Topic

Batch file in Java  RSS feed

 
Nitish Nagar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Need java code for two command prompt operations to work simultaneously:
1) Take input of (network build path) from user. [using Jtext field]
2) go to batch filepath. [MyBatch.bat]
3) Run batch file followed by (network build path). [\\build\mc1\ms2\]

Example:

Open CMD
C:\Users\Dennis\Desktop>
C:\Users\Dennis\Desktop\MyCode>MyBatch.bat \\build\mc1\ms2\

\\build\mc1\ms2\ - We will get from user using JTextField

I have already created java code to run batch file from specific path but not able to link with user input \\build\mc1\ms2\.

Also, this output should be returned to Jscrollpane. This is also independently working for me using cmd but not for batch file.

Code:



Thanks
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to provide lots more details about what happens when you run that code with or without a GUI. What happens if you run the code in an ordinary method rather than action performed? Why are you using that most dreadful method read()? Why didn't you wrap that Stream in a buffered reader? What are you doing with the Process's error stream? Most important, have you understood the classic article by Michael Daconta called When Runtime.exec won't. Don't go anywhere near exec until you understand that. You can use a ProcessBuilder object to make it easier, but Daconta's principles still apply.
 
Nitish Nagar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Campbell, As per your comment i will wrap read() in a buffered reader and remove redundancy with error stream.

In both cases (with and without GUI) code is working fine and executing the batch file as indicated above through runtime.exec. Also, I am able to take user input through TextF and storing in str.
Now, focussing on problem statement, i want to merge batch file and str to work at same time (.bat followed by str) using command prompt. Is it possible to achieve ?

how we can access the values from java file into batch file from %1, %2, %3 ?

Please help me in getting this executed..
thanks a lot !!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!