1

I am trying to create a desktop application (created in java) which will internally run jcshell (tool from NXP which is used to interact with secure element SD card from computer) and produce the output. In jcshell I will be running script file. So this desktop application also should start jcshell internally and run the script file.

I have executed JCOP shell commands which will communicate to secure element SD card through JCOP shell tool (jcshell.bat) provided by JCOP(NXP). Now I need to create a windows desktop application through which I should be able to run JCOP shell commands through jcshell.bat.

Process processObj = Runtime.getRuntime().exec("cmd /C dir");

The above code will return same output from command prompt as well as from my custom java desktop application with details of the directory. I am looking for something similar , but could not get jcshell.bat running from my JavaDesktopApplication.

Any help on the above will be really appreciated

I have tried to work with ProcessBuilder also in the following way, but could not get the expected output.In the following arraylist, first element is the path of my batch file and second element is the location of script file.My intention is to run the script file through windows application which is jcshell.bat which I used to run with the tool given by JCOP.Following is the code using ProcessBuilder.

ArrayList commandList = new ArrayList<String>();
commandList.add("C:\\Program Files\\NXP Semiconductors\\JCShell\\jcshell.bat");
commandList.add("./scripts/javatest.jcsh");‌​‌​
ProcessBuilder pb = new ProcessBuilder(commandList);
pb.redirectErrorStream(true);
Process p = pb.start();
String s;
BufferedReader stdout = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((s = stdout.readLine()) != null && !isCancelled()) {
    publish(s);
    System.out.println("OUTPUT == " + s);
}
if (!isCancelled()) {
    status = p.waitFor();
}
p.getInputStream().close();
p.getOutputStream().close();
p.destroy();
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Sreehari
  • 5,621
  • 2
  • 25
  • 59
  • Also consider `ProcessBuilder`, illustrated [here](http://stackoverflow.com/search?tab=newest&q=user%3a230513%20ProcessBuilder). – trashgod Jan 15 '14 at 16:29
  • @trashgod : Can you pls look at the code above in which I have used ProcessBuilder. I have added the commands to arraylist. Arraylist's first element is having the path to the jcshell. Second element is having the command to execute a script file. Now while running only the first element in commandlist gets executed but not the second (which is exactly what i need the program to do) – Sreehari Jan 16 '14 at 09:48
  • Please edit your question to include a [*Minimal, Complete, Valid Example*](http://stackoverflow.com/help/mcve) that shows your current approach. Perhaps someone with JCOP experience can advise you. – trashgod Jan 16 '14 at 11:33
  • @trashgod : I have edited my question for better clarity. Hope this clarified the issue. – Sreehari Jan 16 '14 at 13:38
  • 1
    I don't think you can _sequence_ command like that; I think you have to run one, check the output, run another, check the output, etc. +1 for update. – trashgod Jan 16 '14 at 14:24
  • There is a static method in the `JCShell` class you can call, but I can only get to my desk on monday, so happy searching. The API doc is in the Eclipse help. OK, gotta sleep, my typing is getting erratic. – Maarten Bodewes Jan 17 '14 at 00:26
  • I am trying with the inputs. Will get back to you guys once concluding. – Sreehari Jan 17 '14 at 10:47
  • Tried many trial and errors with the problem. I am able to either open the jcshell.bat through one way or getting the starting sysout which are written in jcshell. Till now I am not able to run my script file or get an expected output. Can somebody give some inputs for the same? – Sreehari Jan 20 '14 at 12:59
  • 2
    I got the answer finally.... This link [Stack over flow only](http://stackoverflow.com/questions/4157303/how-to-execute-cmd-commands-via-java) explains it perfectly – Sreehari Jan 22 '14 at 14:10

1 Answers1

0

The answer is exactly given over here.. [Stackoverflow] (How to execute cmd commands via Java) Thank you all for the support given...

Community
  • 1
  • 1
Sreehari
  • 5,621
  • 2
  • 25
  • 59