3

I am trying to add a Java from to a Visual Prolog generated executable by running it as a process.

I have used this answer to implement the process interaction. My Visual Prolog expects a number from the command line, it even validates it (whether it is a Prolog term or not), but when running from Java, it does not recognize input as valid. Are those scape chars turning my number into a string?

When I try to remove them, my Java program hungs and the Visual Prolog executable does not respond. I think it is like pressing the enter button.

Community
  • 1
  • 1
Kookoriko
  • 322
  • 1
  • 3
  • 11
  • It seems it is something with Visual Prolog, as the Visual Prolog executable itself runs ok, and the interface is sending correctly the number, but somehow Visual Prolog does not recognize correctly at my custom function or in toTerm/1. Thanks for the comments. But I am not sure if I should delete the question... – Kookoriko Dec 22 '13 at 05:38

4 Answers4

1

\r\n is an EOL (end-of-line) sequence in Windows.

If the input is read line-oriented then the consuming code won't process the line until EOL (or EOF) is sent - this will make the consumer appear to "hang" while it's really juts patiently waiting for the rest of the line. Consider Scanner.nextLine in Java: nextLine won't return until a full line is ready!

Solution: send the EOL with the appropriate input to Visual Prolog; or close the input stream.


Also see also "line.separator", perhaps. However, the various println (print line) methods should already include the appropriate EOL.

Community
  • 1
  • 1
user2864740
  • 60,010
  • 15
  • 145
  • 220
0

\r is carriage return CR \n is linefeed LF

many textual protocols require you to use CR+LF and some require to recognize on LF.

It is like starting a newline in text in Windows

Saher Ahwal
  • 9,015
  • 32
  • 84
  • 152
0

It's necessary if and only if the target process requires it.

You state that your process 'requires a number from the command line', but if you're feeding it input through its 'stdin' that can't be the case.

Instead it appears to require a number via a line entered to the console.

In either case the word 'line' indicates the need for a line terminator.

user207421
  • 305,947
  • 44
  • 307
  • 483
0

The referenced example is using pipes (redirecting stdin and stdout) to communicate between the processes, but you say your program expects a number on the command line.