0

I am using process builder to execute some windows commands but I am not able to use the stdin < for reading a file. For example, reading the myJOB configuration xml to create a new job called myJOB is working fine in command prompt but not working in eclipse using process builder:

java -jar jenkins-cli.jar -s "url" create-job myJOB < myJOB_Config.xml

Any solutions...

Affi
  • 142
  • 1
  • 1
  • 15
  • `<` is interpreted by the shell. ProcessBuilder won't do that but I guess you could (don't. `redirectInput` is better) build a process that invokes a shell that executes the command. Like `bash -c "command here"`. Similar to http://stackoverflow.com/a/16486906 – zapl Nov 18 '15 at 13:25

1 Answers1

1

Build your command without the < myJOB_Config.xml, then use ProcessBuilder.redirectInput(File).

Sets this process builder's standard input source to a file.

Andy Turner
  • 137,514
  • 11
  • 162
  • 243
  • I tried this...didn't work out. Instead of file, the ProcessBuilder gets java.lang.ProcessBuilder@29be9e36 as argument, in turn throwing error – Affi Nov 18 '15 at 17:18
  • Without seeing your code, there's not much I can say, aside from you've not used the API correctly. – Andy Turner Nov 18 '15 at 17:20
  • This is my code: `code` java -jar jenkins-cli.jar -s "url" create-job myJOB pb1.redirectInput(new File("myJOB_Config.xml")) `code` – Affi Nov 18 '15 at 17:32
  • What you provided is not the whole code. The code would include something like `(new ProcessBuilder("java", "-jar", "jenkins-cli.jar", "-s", url, "create-job", "myJOB")).redirectInput(File)` and some more code around to run the command and read output. – C.A.B. Jul 03 '18 at 23:57