0

I am trying to use ProcessBuild to run the cmd statement.

ProcessBuilder pb = new ProcessBuilder("cmd.exe", "/C", "start");
Process p = pb.start();

However, I can only open the cmd.exe

I do not know how to add statement to the ProcessBuild so that the all the jar in the folder can run. Usually, I open the cmd in the stanford-corenlp-full-2015年12月09日 folder, and add this statement to run: java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer
enter image description here

So how to write this statement Run cmd commands through java?? I am getting errors as the statement consists "*". How to edit the ProcessBuilder so that i can run the statement? Thanks a lot

asked Oct 6, 2016 at 2:39

1 Answer 1

3

You could set the directory from where the command to be executed

 List<String> cmds = Arrays.asList("cmd.exe", "/C", "start", "java", "-mx4g", "-cp", "*", "edu.stanford.nlp.pipeline.StanfordCoreNLPServer");
 ProcessBuilder builder = new ProcessBuilder(cmds);
 builder.directory(new File("D:/stanford-corenlp-full-2015年12月09日"));
 Process proc = builder.start();

UPDATE as requested in comments

 OutputStream out = proc.getOutputStream();
 new Thread(() -> {
 try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out))) {
 bw.write("[command here]");
 bw.flush();
 } catch (IOException ioe) {
 ioe.printStackTrace();
 }
 }).start();
answered Oct 6, 2016 at 2:49
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot! It works. may i ask one question? How to close cmd of the stanford program by using java?
Sorry, may I know how to close the CMD in this case after I finished using Stanfordserver?????? @Saravana

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.