-1

I have an exe file, which I can run from cmd like this:

echo text|majka.exe -f majka.w-lt  //or...
majka.exe -f majka.w-lt < text.txt  //same, but reading text from file

I want to send this command from java. I know I can use ProcessBuilder like this:

String text = "text";
ProcessBuilder pb = new ProcessBuilder("C:\\majkawin\\majka.exe", "-f", "majka.w-lt");
pb.start();

but I don't know how to send String text by pipe to this command. I prefer solution without creating text.txt file if it is possible.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Pivoman
  • 4,435
  • 5
  • 18
  • 30

1 Answers1

0

pb.start() returns a Process, which has input and output streams, which you can read from and write to.

This is all documented.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • Thanks for your RTFM answer, but can you give me an example? I looked on Process class before, but there is only getInput/Output/ErrorStream method. How you can use it after Process is started? – Pivoman Feb 16 '18 at 10:41
  • TBF @Pivoman, had you put in your question, 'I've looked at Process class before, but there are only getInput/Output/ErrorStream methods. How you can use it after Process is started?' You would have been less likely to receive a RTFM type answer! – Compo Feb 16 '18 at 16:39
  • @Compo If I should write there my whole days research, someone could use another fancy shortcut "TL;DR". :D Anyway, I admit, that I'm not a master of cmd and I found, that I can use in cmd only majka.exe -f majka.w-lt (without pipe) and write inputs there. So this answer was eventually little helpful and I will accept it. Better answer I finally found here: https://stackoverflow.com/a/38068513/3125587 – Pivoman Feb 18 '18 at 15:13