Command line save and quit

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Command line save and quit

K K Subbu
Hi,

STCommandLineHandler>>#end is defined as:
---
        | quit  |
        quit := self commandLine hasOption: 'quit'.
        (self commandLine hasOption: 'save')
                ifTrue: [ Smalltalk snapshot: true andQuit: quit ].
        quit
                ifTrue: [ self exitSuccess ].
---
Can this be simplified to:

        ^Smalltalk snapshot: (self hasOption: 'save')
                  andQuit:  (self hasOption: 'quit')

Is it necessary to call exitSuccess when only '--quit' is given?

Regards .. Subbu

Reply | Threaded
Open this post in threaded view
|

Re: Command line save and quit

Max Leske

> On 17 May 2017, at 13:29, K K Subbu <[hidden email]> wrote:
>
> Hi,
>
> STCommandLineHandler>>#end is defined as:
> ---
> | quit  |
> quit := self commandLine hasOption: 'quit'.
> (self commandLine hasOption: 'save')
> ifTrue: [ Smalltalk snapshot: true andQuit: quit ].
> quit
> ifTrue: [ self exitSuccess ].
> ---
> Can this be simplified to:
>
> ^Smalltalk snapshot: (self hasOption: 'save')
>  andQuit:  (self hasOption: 'quit')
>
> Is it necessary to call exitSuccess when only '--quit' is given?

Yes. #exitSuccess does a bit more:
1. return an exit code to the command line
2. print a message
3. check if the session has changed
4. allows for overriding and special handling of the Exit exception.

You should not assume that nobody needs that :)

Cheers,
Max

>
> Regards .. Subbu
>


Reply | Threaded
Open this post in threaded view
|

Re: Command line save and quit

K K Subbu
On Wednesday 17 May 2017 05:12 PM, Max Leske wrote:
> Yes. #exitSuccess does a bit more:
> 1. return an exit code to the command line
> 2. print a message
> 3. check if the session has changed
> 4. allows for overriding and special handling of the Exit exception.
>
> You should not assume that nobody needs that :)

Thanks for the quick clarification. I am trying to understand the
difference between using quit and save/quit. exitSuccess never gets
called when both options "--save --quit" are given. Shouldn't the code
handle this case as well:

        (self hasOption: 'save')
                ifTrue: [ Smalltalk snapshot: true andQuit: false ].
        (self hasOption: 'quit')
                ifTrue: [ self exitSuccess ].

Regards .. Subbu

Reply | Threaded
Open this post in threaded view
|

Re: Command line save and quit

Max Leske

> On 17 May 2017, at 14:24, K K Subbu <[hidden email]> wrote:
>
> On Wednesday 17 May 2017 05:12 PM, Max Leske wrote:
>> Yes. #exitSuccess does a bit more:
>> 1. return an exit code to the command line
>> 2. print a message
>> 3. check if the session has changed
>> 4. allows for overriding and special handling of the Exit exception.
>>
>> You should not assume that nobody needs that :)
>
> Thanks for the quick clarification. I am trying to understand the difference between using quit and save/quit. exitSuccess never gets called when both options "--save --quit" are given. Shouldn't the code handle this case as well:
>
> (self hasOption: 'save')
> ifTrue: [ Smalltalk snapshot: true andQuit: false ].
> (self hasOption: 'quit')
> ifTrue: [ self exitSuccess ].

Yes, I think so. But you have to be careful there. Imagine that you first save with "Smalltalk snapshot: true andQuit: false" and then you check for 'quit' and send #exitSuccess. What will happen after the next startup is that the execution will arrive at the *same point*. It will check 'quit' and exit as before, you will not be able to get back in to the image.
You should definitely try playing around with that, just be sure to make a copy of your image first :)

Cheers,
Max

>
> Regards .. Subbu
>


Reply | Threaded
Open this post in threaded view
|

Re: Command line save and quit

Damien Pollet
On 17 May 2017 at 14:34, Max Leske <[hidden email]> wrote:
>       (self hasOption: 'save')
>               ifTrue: [ Smalltalk snapshot: true andQuit: false ].
>       (self hasOption: 'quit')
>               ifTrue: [ self exitSuccess ].

Yes, I think so. But you have to be careful there. Imagine that you first save with "Smalltalk snapshot: true andQuit: false" and then you check for 'quit' and send #exitSuccess.

But in this version the lookup for option quit is done again when the images wakes up. Compare to the version originally copied by Subbu:

        | quit  |
        quit := self commandLine hasOption: 'quit'.
        (self commandLine hasOption: 'save')
                ifTrue: [ Smalltalk snapshot: true andQuit: quit ].
        quit
                ifTrue: [ self exitSuccess ].

Here I'm guessing if you --save --quit then the image will get saved, and next time it wakes up, enters the second conditional and #exitSuccess… confusing :/

--
Damien Pollet
type less, do more [ | ] http://people.untyped.org/damien.pollet
Reply | Threaded
Open this post in threaded view
|

Re: Command line save and quit

Max Leske

On 17 May 2017, at 15:23, Damien Pollet <[hidden email]> wrote:

On 17 May 2017 at 14:34, Max Leske <[hidden email]> wrote:
>       (self hasOption: 'save')
>               ifTrue: [ Smalltalk snapshot: true andQuit: false ].
>       (self hasOption: 'quit')
>               ifTrue: [ self exitSuccess ].

Yes, I think so. But you have to be careful there. Imagine that you first save with "Smalltalk snapshot: true andQuit: false" and then you check for 'quit' and send #exitSuccess.

But in this version the lookup for option quit is done again when the images wakes up. Compare to the version originally copied by Subbu:

        | quit  |
        quit := self commandLine hasOption: 'quit'.
        (self commandLine hasOption: 'save')
                ifTrue: [ Smalltalk snapshot: true andQuit: quit ].
        quit
                ifTrue: [ self exitSuccess ].

Here I'm guessing if you --save --quit then the image will get saved, and next time it wakes up, enters the second conditional and #exitSuccess… confusing :/

Very. When I look at this code, without going into the image and look, I would say that it will lead to exactly what I described: the image will start and exit again immediately. 


--
Damien Pollet
type less, do more [ | ] http://people.untyped.org/damien.pollet

Reply | Threaded
Open this post in threaded view
|

Re: Command line save and quit

K K Subbu
In reply to this post by Damien Pollet
On Wednesday 17 May 2017 06:53 PM, Damien Pollet wrote:

>
>         | quit  |
>         quit := self commandLine hasOption: 'quit'.
>         (self commandLine hasOption: 'save')
>                 ifTrue: [ Smalltalk snapshot: true andQuit: quit ].
>         quit
>                 ifTrue: [ self exitSuccess ].
>
> Here I'm guessing if you --save --quit then the image will get saved,
> and next time it wakes up, enters the second conditional and
> #exitSuccess… confusing :/

Thank you for making it clear. This is what intrigued me. I see many
instances in pharo-project/pharo git where "--save --quit" is used. e.g.

scripts/export.sh:./pharo Pharo.image --save --quit ${PWD}/export.st

Regards .. Subbu