Hi! Interesting idea.

How about something like:

test.pike:

int x = v;

$ pike -e '(program)"test"'

test.pike:1:Undefined identifier x.
Compilation failed.
-:1: PikeCompiler("", UNDEFINED, -1, -1, target, UNDEFINED)->compile()
-:1: DefaultCompilerEnvironment->compile(PikeCompiler("", UNDEFINED, -1, -1, target, UNDEFINED)) /opt/homebrew/Cellar/pike/8.0.1956/libexec/lib/pike/master.pike:743: compile_string("int v = x;\n\n","test.pike",UNDEFINED,test.pike,0,UNDEFINED) /opt/homebrew/Cellar/pike/8.0.1956/libexec/lib/pike/master.pike:1517: master()->low_findprog("test",".pike",UNDEFINED,UNDEFINED) /opt/homebrew/Cellar/pike/8.0.1956/libexec/lib/pike/master.pike:1646: master()->findprog("test","",UNDEFINED,UNDEFINED) /opt/homebrew/Cellar/pike/8.0.1956/libexec/lib/pike/master.pike:1697: master()->low_cast_to_program("test","-",UNDEFINED,UNDEFINED) /opt/homebrew/Cellar/pike/8.0.1956/libexec/lib/pike/master.pike:1719: master()->cast_to_program("test","-",UNDEFINED)
-:2: -()->run(1,({"pike"}))

or maybe something fancier you can test for in your shell script?

$ pike -e 'return catch((program)"test")?1:0'
test.pike:1:Undefined identifier x.
$ echo $?
1

I think there's a way to silence even this output, but I don't remember what it is offhand, probably just as easy to redirect stderr somewhere.

If you want variable substitution to work, such as in a loop or something, you'll need to not use single quotes and escape the double quotes:

for x in *.pike; do
pike -e "return catch((program)\"$x\")?1:0"
echo "$x: $?"
done

Hope this helps!

Bill

On 2025-03-20 18:31, Marcos Cruz wrote:
Is there any way to compile a program but not executing it afterwards,
in order to check just the compilation? I have read the command help and
the man page but found nothing.  There's an `-E` option to run only the
preprocessor, but that's all.

Context: I have 19 little programs (between 50 and 500 LOC) I have
written using Pike 8.0;  after installing 9.0 it occurred to me I could
check possible compilation errors in a simple shell loop, instead of
executing and manually exiting each program; but that's not a big deal
anyways.

Reply via email to