[Pharo-project] VM Exit Value
Hi, For scripting purposes, I would like to use/control the VM exit status/value (on Linux). There is SmalltalkImage>>#snapshot:andQuit: but there is nothing there that indicates that one can set the process exit status. Is there a way to do that ? Has anyone a good idea on how the CogVM could communicate back to its invoking script whether is ran OK or not ? Thx, Sven
Not nice, but works reasonably well. The invoking script "listens" to Pharo generating some output file. Have a look at builder.sh, it does that. Lukas On Friday, 25 November 2011, Sven Van Caekenberghe <sven@beta9.be> wrote:
Hi,
For scripting purposes, I would like to use/control the VM exit status/value (on Linux).
There is SmalltalkImage>>#snapshot:andQuit: but there is nothing there that indicates that one can set the process exit status. Is there a way to do that ?
Has anyone a good idea on how the CogVM could communicate back to its invoking script whether is ran OK or not ?
Thx,
Sven
-- Lukas Renggli (mobile) http://www.lukas-renggli.ch
On 25 Nov 2011, at 09:37, Lukas Renggli wrote:
Not nice, but works reasonably well. The invoking script "listens" to Pharo generating some output file. Have a look at builder.sh, it does that.
Thx, I knew about that one. And indeed, it does seems to work, but it is not very nice compared to how everything else in *nix is supposed to work. Sven
sven could you add an entry on the cog bug tracker? Stef On Nov 25, 2011, at 9:48 AM, Sven Van Caekenberghe wrote:
On 25 Nov 2011, at 09:37, Lukas Renggli wrote:
Not nice, but works reasonably well. The invoking script "listens" to Pharo generating some output file. Have a look at builder.sh, it does that.
Thx, I knew about that one. And indeed, it does seems to work, but it is not very nice compared to how everything else in *nix is supposed to work.
Sven
On 25 Nov 2011, at 16:09, Stéphane Ducasse wrote:
sven could you add an entry on the cog bug tracker?
There is already support for that in platform-specific code. The function is sqInt ioExitWithErrorCode(int); so, the only thing which we need is to change the #primitiveQuit to see if there an extra argument to it, and then call that function instead of ioExit looks like easy to do. Btw, actually Cog VMs already doing that: primitiveQuit self ioExitWithErrorCode: (argumentCount = 1 ifTrue: [objectMemory integerValueOf: self stackTop] ifFalse: [0]) so.. you need only 1 thing: add one more method to Smalltalk: quitPrimitive: exitCode "Primitive. Exit to another operating system on the host machine, if one exists. All state changes in the object space since the last snapshot are lost. Essential. See Object documentation whatIsAPrimitive." <primitive: 113> self primitiveFailed so you can use it right now. -- Best regards, Igor Stasenko.
in the bug tracker please :) On Nov 25, 2011, at 4:59 PM, Igor Stasenko wrote:
There is already support for that in platform-specific code. The function is sqInt ioExitWithErrorCode(int);
so, the only thing which we need is to change the #primitiveQuit
to see if there an extra argument to it, and then call that function instead of ioExit
looks like easy to do.
Btw, actually Cog VMs already doing that:
primitiveQuit
self ioExitWithErrorCode: (argumentCount = 1 ifTrue: [objectMemory integerValueOf: self stackTop] ifFalse: [0])
so.. you need only 1 thing:
add one more method to Smalltalk:
quitPrimitive: exitCode "Primitive. Exit to another operating system on the host machine, if one exists. All state changes in the object space since the last snapshot are lost. Essential. See Object documentation whatIsAPrimitive."
<primitive: 113> self primitiveFailed
so you can use it right now.
-- Best regards, Igor Stasenko.
Yes, it works! if i open image like that: ./results/NBCog.app/Contents/MacOS/NBCog ./image/generator.image ; echo $? and then do: Smalltalk quitPrimitive: 10 it prints: 10 On 25 November 2011 17:01, Stéphane Ducasse <stephane.ducasse@inria.fr> wrote:
in the bug tracker please :)
On Nov 25, 2011, at 4:59 PM, Igor Stasenko wrote:
There is already support for that in platform-specific code. The function is sqInt ioExitWithErrorCode(int);
so, the only thing which we need is to change the #primitiveQuit
to see if there an extra argument to it, and then call that function instead of ioExit
looks like easy to do.
Btw, actually Cog VMs already doing that:
primitiveQuit
   self ioExitWithErrorCode: (argumentCount = 1 ifTrue: [objectMemory integerValueOf: self stackTop] ifFalse: [0])
so.. you need only 1 thing:
add one more method to Smalltalk:
quitPrimitive: exitCode    "Primitive. Exit to another operating system on the host machine, if one    exists. All state changes in the object space since the last snapshot are lost.    Essential. See Object documentation whatIsAPrimitive."
   <primitive: 113>    self primitiveFailed
so you can use it right now.
-- Best regards, Igor Stasenko.
-- Best regards, Igor Stasenko.
Thank you! On 25 Nov 2011, at 17:06, Igor Stasenko wrote:
Yes, it works!
if i open image like that: ./results/NBCog.app/Contents/MacOS/NBCog ./image/generator.image ; echo $?
and then do: Smalltalk quitPrimitive: 10
it prints: 10
On 25 November 2011 17:01, Stéphane Ducasse <stephane.ducasse@inria.fr> wrote:
in the bug tracker please :)
On Nov 25, 2011, at 4:59 PM, Igor Stasenko wrote:
There is already support for that in platform-specific code. The function is sqInt ioExitWithErrorCode(int);
so, the only thing which we need is to change the #primitiveQuit
to see if there an extra argument to it, and then call that function instead of ioExit
looks like easy to do.
Btw, actually Cog VMs already doing that:
primitiveQuit
self ioExitWithErrorCode: (argumentCount = 1 ifTrue: [objectMemory integerValueOf: self stackTop] ifFalse: [0])
so.. you need only 1 thing:
add one more method to Smalltalk:
quitPrimitive: exitCode "Primitive. Exit to another operating system on the host machine, if one exists. All state changes in the object space since the last snapshot are lost. Essential. See Object documentation whatIsAPrimitive."
<primitive: 113> self primitiveFailed
so you can use it right now.
-- Best regards, Igor Stasenko.
On 25 November 2011 17:01, Stéphane Ducasse <stephane.ducasse@inria.fr> wrote:
in the bug tracker please :)
done: http://code.google.com/p/pharo/issues/detail?id=5029 -- Best regards, Igor Stasenko.
On 25 Nov 2011, at 09:27, Sven Van Caekenberghe wrote:
For scripting purposes, I would like to use/control the VM exit status/value (on Linux).
There is SmalltalkImage>>#snapshot:andQuit: but there is nothing there that indicates that one can set the process exit status. Is there a way to do that ?
Has anyone a good idea on how the CogVM could communicate back to its invoking script whether is ran OK or not ?
I think I found something else that might be helpful, but I have not yet worked it out fully. Basically using the #stdout stream in 1.3 it is very easy to generate ouput (this is really a very cool feature!). This script will produce either 'OK' or 'FAILED' depending on the #signalling (and produce a PharoDebug.log file as well): FileStream stdout wantsLineEndConversion: true. [ Error signal: 'Something went terribly wrong'. FileStream stdout nextPutAll: 'OK'; cr. ] on: Error do: [ :exception | Smalltalk logError: exception description inContext: exception signalerContext. FileStream stdout nextPutAll: 'FAILED'; cr. ]. Smalltalk snapshot: false andQuit: true. The problem with this technique is that you cannot use stdout for anything else. Sven
participants (4)
-
Igor Stasenko -
Lukas Renggli -
Stéphane Ducasse -
Sven Van Caekenberghe