2

I have a script named stdout.wl:

While[True, Pause[0.001]; WriteString[OutputStream["stdout", 1], RandomInteger[]//ToString//(#<>"\r\n")&]]

I have another script named stdin.wl:

While[True, Pause[0.001]; Print[InputString[]]]

Run them in commandline:

WolframKernel -script stdout.wl | WolframKernel -script stdin.wl

It works well, the terminal prints those random integers generated from the first script to the second one.

Now I want to remove the \r\ns from the stdout.wl:

While[True, Pause[0.001]; WriteString[OutputStream["stdout", 1], RandomInteger[]//ToString]]

I wonder how should I change the stdin.wl to make this work again:

While[True, Pause[0.001]; Print[(*somefunction[]*)]]

I've tried the answers under

But none of them works.

Thanks.

kenkangxgwe
  • 93
  • 1
  • 8
  • Have you tried StringTrim[...] or StringReplace[..., "\r\n" -> ""]? – flinty Sep 10 '20 at 11:59
  • Which version of MMA are you running? I am running MMA 12.1 under Windows 10. Here your code works flawless, with and without the "//(#<>"\r\n")&" – Daniel Huber Sep 10 '20 at 18:53
  • Hi @flinty, The Problem is given what is output from stdout.wl, I need to read them using stdin.wl. Is not about reading those \r\n and remove them later. – kenkangxgwe Sep 12 '20 at 03:29
  • Hi @DanielHuber, On windows 10, did you run wolfram.exe -script stdout.wl | wolfram.exe -script stdin.wl instead? Running WolframKernel.exe will open up a GUI window which is not desired. – kenkangxgwe Sep 12 '20 at 03:31
  • Here MMA 12.0, Linux x86. The first script prints out the integers, the second prints nothing (no error). – anderstood Sep 19 '20 at 16:55
  • Use [http://reference.wolfram.com/language/ref/RecordSeparators.html] is postprocessing step using chunks of the stream in [http://reference.wolfram.com/language/ref/ReadList.html]. – Steffen Jaeschke Sep 20 '20 at 10:52
  • Hi @anderstood, I was asking to add some function in the (*somefunction[]*) comment so it can print the output of stdout.wl – kenkangxgwe Oct 01 '20 at 06:19
  • @kenkangxgwe I had understood. I was just confirming the behaviour. Have you tried Steffen's suggestion? – anderstood Oct 01 '20 at 06:55
  • @anderstood, Yes I tried, but ReadList with Record and RecordSeparators didn't help. – kenkangxgwe Oct 08 '20 at 07:10
  • @SteffenJaeschke, using ReadList with Record and RecordSeparators didn't help. – kenkangxgwe Oct 08 '20 at 07:10

0 Answers0