Questions about standalone application behavior
Kyle Marple <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
Hi,
I've been using SWI to create standalone executables for a project coded in
Prolog. Everything works correctly, but the behavior of the resulting executable
leaves a few things to be desired. I've searched through the manual for options
with no luck, so I'm hoping someone can help me with the following questions:
1. Is it possible to redirect a file to the standard input of an executable
produced by SWI?
One would normally expect that the command:
'program.exe <input.txt'
would result in program.exe being able to read the contents of input.txt from
STDIN (current_input?). However, the executables SWI produces don't do this. In
fact, they don't seem to do *anything*. They crash before running the first line
of my program.
Here's a simple example:
main :-
write('This is a test!\n'),
read_file(stdin),
halt.
main :-
halt(1).
read_file(Input) :-
get_char(Input, Char),
read_file2(Input, Char).
read_file2(_, Char) :-
Char = end_of_file,
!.
read_file2(Input, Char) :-
write(Char),
get_char(Input, Char2),
!,
read_file2(Input, Char2).
This is compiled with the command:
swipl --goal=main --stand_alone=true --quiet -o test -c test.pl
When run without input redirection (just 'test.exe'), it works as expected,
printing "This is a test!" and then the input received from the keyboard.
However, if 'test.exe < input.txt' is run, where input.txt contains only the
line "Hello World!", it appears to fail and return to the command-line
immediately. There's no output of any kind. Even the initial write statement is
never executed. Is there a way around this? Am I doing something wrong?
2. In most command-line applications, Ctrl+C would terminate the program. Is it
possible to get executables produced by SWI to behave that way?
Currently, the first Ctrl+C is intercepted, giving the user a prompt from the
interpreter. From the manual, it seems like the --nosignals switch might solve
this, but it doesn't. Additionally, the flag indicates that signals are already
disabled.
3. Is it possible to compile an executable that can run on a system without SWI
installed?
I would like to distribute binaries for my project, but the compiled executables
still rely on libswipl.dll (on Windows). Additionally, the DLL must match the
executable, insofar as a 32-bit executable requires a 32-bit libswipl.dll, so a
person with only 64-bit SWI installed can't run the 32-bit binary. Is there a
way to remove this dependency?
Sincerely,
Kyle Marple