Execute a script from command line save image and exit

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

Execute a script from command line save image and exit

kilon.alios
How to execute a script from command line , then save the image and exit ?

I use the st command but it offers either --save which saves but keeps image opened or --exit the exits the image without saving

./pharo Ephestos.image st --save  test.st
Reply | Threaded
Open this post in threaded view
|

Re: Execute a script from command line save image and exit

Thierry Goubier


2016-11-28 12:13 GMT+01:00 Dimitris Chloupis <[hidden email]>:
How to execute a script from command line , then save the image and exit ?

I use the st command but it offers either --save which saves but keeps image opened or --exit the exits the image without saving

./pharo Ephestos.image st --save  test.st

Use an option like -vm-display-null with -save. There is also a --nodisplay option.

Thierry
 

Reply | Threaded
Open this post in threaded view
|

Re: Execute a script from command line save image and exit

kilon.alios
there are two binaries one is pharo-ui that displays the gui and one is pharo that does not use the GUI , because I use pharo and not pharo-ui , i do not need -vm-display-null and does not solve my problem of not exiting 


On Mon, Nov 28, 2016 at 1:25 PM Thierry Goubier <[hidden email]> wrote:
2016-11-28 12:13 GMT+01:00 Dimitris Chloupis <[hidden email]>:
How to execute a script from command line , then save the image and exit ?

I use the st command but it offers either --save which saves but keeps image opened or --exit the exits the image without saving

./pharo Ephestos.image st --save  test.st

Use an option like -vm-display-null with -save. There is also a --nodisplay option.

Thierry
 

Reply | Threaded
Open this post in threaded view
|

Re: Execute a script from command line save image and exit

Thierry Goubier


2016-11-28 12:54 GMT+01:00 Dimitris Chloupis <[hidden email]>:
there are two binaries one is pharo-ui that displays the gui and one is pharo that does not use the GUI , because I use pharo and not pharo-ui , i do not need -vm-display-null and does not solve my problem of not exiting 

Then this is strange because, as you remember from the Makefile (and because my line of work is command-line oriented), I use the pharo shell script to run a script and either save the image or not save the image, never opening the window in all cases.

Thierry
 


On Mon, Nov 28, 2016 at 1:25 PM Thierry Goubier <[hidden email]> wrote:
2016-11-28 12:13 GMT+01:00 Dimitris Chloupis <[hidden email]>:
How to execute a script from command line , then save the image and exit ?

I use the st command but it offers either --save which saves but keeps image opened or --exit the exits the image without saving

./pharo Ephestos.image st --save  test.st

Use an option like -vm-display-null with -save. There is also a --nodisplay option.

Thierry
 


Reply | Threaded
Open this post in threaded view
|

Re: Execute a script from command line save image and exit

kilon.alios
can you provide a link to your makefile, maybe I do something stupid, I am very noob when it comes to command line cause I use GUIs 99% of the time


On Mon, Nov 28, 2016 at 1:59 PM Thierry Goubier <[hidden email]> wrote:
2016-11-28 12:54 GMT+01:00 Dimitris Chloupis <[hidden email]>:
there are two binaries one is pharo-ui that displays the gui and one is pharo that does not use the GUI , because I use pharo and not pharo-ui , i do not need -vm-display-null and does not solve my problem of not exiting 

Then this is strange because, as you remember from the Makefile (and because my line of work is command-line oriented), I use the pharo shell script to run a script and either save the image or not save the image, never opening the window in all cases.

Thierry
 


On Mon, Nov 28, 2016 at 1:25 PM Thierry Goubier <[hidden email]> wrote:
2016-11-28 12:13 GMT+01:00 Dimitris Chloupis <[hidden email]>:
How to execute a script from command line , then save the image and exit ?

I use the st command but it offers either --save which saves but keeps image opened or --exit the exits the image without saving

./pharo Ephestos.image st --save  test.st

Use an option like -vm-display-null with -save. There is also a --nodisplay option.

Thierry
 

Reply | Threaded
Open this post in threaded view
|

Re: Execute a script from command line save image and exit

Thierry Goubier
The GitFileTree-MergeDriver is a good place for that since it has a Makefile[1] with smalltalk scripting inside ("eval"), and a command line handler[2] to handle being used on the command line[3] by git.

[1] https://github.com/ThierryGoubier/GitFileTree-MergeDriver/blob/master/Makefile
[2] https://github.com/ThierryGoubier/GitFileTree-MergeDriver/tree/master/GitFileTree-MergeDriver.package/GitFileTreeMergeCommandLine.class
[3] https://github.com/ThierryGoubier/GitFileTree-MergeDriver/blob/master/merge

2016-11-28 13:01 GMT+01:00 Dimitris Chloupis <[hidden email]>:
can you provide a link to your makefile, maybe I do something stupid, I am very noob when it comes to command line cause I use GUIs 99% of the time


On Mon, Nov 28, 2016 at 1:59 PM Thierry Goubier <[hidden email]> wrote:
2016-11-28 12:54 GMT+01:00 Dimitris Chloupis <[hidden email]>:
there are two binaries one is pharo-ui that displays the gui and one is pharo that does not use the GUI , because I use pharo and not pharo-ui , i do not need -vm-display-null and does not solve my problem of not exiting 

Then this is strange because, as you remember from the Makefile (and because my line of work is command-line oriented), I use the pharo shell script to run a script and either save the image or not save the image, never opening the window in all cases.

Thierry
 


On Mon, Nov 28, 2016 at 1:25 PM Thierry Goubier <[hidden email]> wrote:
2016-11-28 12:13 GMT+01:00 Dimitris Chloupis <[hidden email]>:
How to execute a script from command line , then save the image and exit ?

I use the st command but it offers either --save which saves but keeps image opened or --exit the exits the image without saving

./pharo Ephestos.image st --save  test.st

Use an option like -vm-display-null with -save. There is also a --nodisplay option.

Thierry
 


Reply | Threaded
Open this post in threaded view
|

Re: Execute a script from command line save image and exit

Sven Van Caekenberghe-2
In reply to this post by kilon.alios
Hi Dimitris,

According to

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

You should be able to combine --quit and --save to get the desired effect but I haven't tested it.

BTW, command line usage of Pharo works very well (and has been working well for years).

Sven

> On 28 Nov 2016, at 12:13, Dimitris Chloupis <[hidden email]> wrote:
>
> How to execute a script from command line , then save the image and exit ?
>
> I use the st command but it offers either --save which saves but keeps image opened or --exit the exits the image without saving
>
> ./pharo Ephestos.image st --save  test.st


Reply | Threaded
Open this post in threaded view
|

Re: Execute a script from command line save image and exit

philippeback
I have been doing like this:

#!/bin/bash
./pharo Pharo.image save Builder
./pharo Builder.image LoadBuilder.st --quit

and LoadBuilder.st contains

<code to load configurations and other thing>
Smalltalk saveSession.

Worked for me in a 3.0, so should still be fine.

I could then to a set of images with various names and builders so one could have all the prerequisites and the last step just loaded my code fast on my CI.


Phil


On Mon, Nov 28, 2016 at 1:23 PM, Sven Van Caekenberghe <[hidden email]> wrote:
Hi Dimitris,

According to

STCommandLineHandler>>#end
        | quit  |

        quit := self commandLine hasOption: 'quit'.

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

        quit
                ifTrue: [ self exitSuccess ].

You should be able to combine --quit and --save to get the desired effect but I haven't tested it.

BTW, command line usage of Pharo works very well (and has been working well for years).

Sven

> On 28 Nov 2016, at 12:13, Dimitris Chloupis <[hidden email]> wrote:
>
> How to execute a script from command line , then save the image and exit ?
>
> I use the st command but it offers either --save which saves but keeps image opened or --exit the exits the image without saving
>
> ./pharo Ephestos.image st --save  test.st




Reply | Threaded
Open this post in threaded view
|

Re: Execute a script from command line save image and exit

kilon.alios
In reply to this post by Thierry Goubier


On Mon, Nov 28, 2016 at 2:13 PM Thierry Goubier <[hidden email]> wrote:
The GitFileTree-MergeDriver is a good place for that since it has a Makefile[1] with smalltalk scripting inside ("eval"), and a command line handler[2] to handle being used on the command line[3] by git.


yeah problem is eval works fine for me too. 

I have been doing like this:

#!/bin/bash
./pharo Pharo.image save Builder
./pharo Builder.image LoadBuilder.st --quit

and LoadBuilder.st contains

<code to load configurations and other thing>
Smalltalk saveSession.

Worked for me in a 3.0, so should still be fine.

I could then to a set of images with various names and builders so one could have all the prerequisites and the last step just loaded my code fast on my CI."

Yeap that works but I found a nasty bug, pharo has issues when ! is contained inside a string so this code works

```Smalltalk

Object subclass:#HelloWorld.
HelloWorld class compile:
'run
Transcript show: ''Hello World'' ;cr.
Transcript show: ''Yes we did it again'' ;cr.
^self ' classified: #run.
HelloWorld run.
Smalltalk saveSession.

```

but this code produces an error if contained in a st file

```Smalltalk

Object subclass:#HelloWorld.
HelloWorld class compile:
'run
Transcript show: ''Hello World'' ;cr.
Transcript show: ''Yes we did it again!'' ;cr.
^self ' classified: #run.
HelloWorld run.
Smalltalk saveSession.

```
if the code is passed as eval it works fine. I assume here is because ! is used to define metadata inside a st file. 
Reply | Threaded
Open this post in threaded view
|

Re: Execute a script from command line save image and exit

Thierry Goubier


2016-11-28 14:28 GMT+01:00 Dimitris Chloupis <[hidden email]>:


On Mon, Nov 28, 2016 at 2:13 PM Thierry Goubier <[hidden email]> wrote:
The GitFileTree-MergeDriver is a good place for that since it has a Makefile[1] with smalltalk scripting inside ("eval"), and a command line handler[2] to handle being used on the command line[3] by git.


yeah problem is eval works fine for me too. 

I have been doing like this:

#!/bin/bash
./pharo Pharo.image save Builder
./pharo Builder.image LoadBuilder.st --quit

and LoadBuilder.st contains

<code to load configurations and other thing>
Smalltalk saveSession.

Worked for me in a 3.0, so should still be fine.

I could then to a set of images with various names and builders so one could have all the prerequisites and the last step just loaded my code fast on my CI."

Yeap that works but I found a nasty bug, pharo has issues when ! is contained inside a string so this code works

```Smalltalk

Object subclass:#HelloWorld.
HelloWorld class compile:
'run
Transcript show: ''Hello World'' ;cr.
Transcript show: ''Yes we did it again'' ;cr.
^self ' classified: #run.
HelloWorld run.
Smalltalk saveSession.

```

but this code produces an error if contained in a st file

```Smalltalk

Object subclass:#HelloWorld.
HelloWorld class compile:
'run
Transcript show: ''Hello World'' ;cr.
Transcript show: ''Yes we did it again!'' ;cr.
^self ' classified: #run.
HelloWorld run.
Smalltalk saveSession.

```
if the code is passed as eval it works fine. I assume here is because ! is used to define metadata inside a st file. 

Yes, I'd guess that you are triggering the !! delimited reading when you give a .st. In short, giving a .st file as an argument triggers a FileIn operation, not an execute smalltalk script.

It just happens that FileIn is an executable format (sort of), so you can use it as a script engine until you reach such issues.

Thierry
Reply | Threaded
Open this post in threaded view
|

Re: Execute a script from command line save image and exit

Damien Pollet-2
In reply to this post by Sven Van Caekenberghe-2
So… if I read that code correctly, when you pass both --save and --quit, the image will first save itself and quit (with an unspecified return code, or the one picked by the snapshot code). Then, next time you run this image, it will resume execution and exit immediately (that time with an explicit success return code).

*¬_¬ not sure if stupid code or stupid me*

On 28 November 2016 at 13:23, Sven Van Caekenberghe <[hidden email]> wrote:
Hi Dimitris,

According to

STCommandLineHandler>>#end
        | quit  |

        quit := self commandLine hasOption: 'quit'.

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

        quit
                ifTrue: [ self exitSuccess ].

You should be able to combine --quit and --save to get the desired effect but I haven't tested it.

BTW, command line usage of Pharo works very well (and has been working well for years).

Sven

> On 28 Nov 2016, at 12:13, Dimitris Chloupis <[hidden email]> wrote:
>
> How to execute a script from command line , then save the image and exit ?
>
> I use the st command but it offers either --save which saves but keeps image opened or --exit the exits the image without saving
>
> ./pharo Ephestos.image st --save  test.st



Reply | Threaded
Open this post in threaded view
|

Re: Execute a script from command line save image and exit

Sven Van Caekenberghe-2

> On 28 Nov 2016, at 15:08, Damien Pollet <[hidden email]> wrote:
>
> So… if I read that code correctly, when you pass both --save and --quit, the image will first save itself and quit (with an unspecified return code, or the one picked by the snapshot code). Then, next time you run this image, it will resume execution and exit immediately (that time with an explicit success return code).
>
> *¬_¬ not sure if stupid code or stupid me*

Yeah, it does not add up, I think the last expression/test should not be there.

This save&quit / resume is sometimes hard to reason about (BTW, I am looking at this in 4.0).

> On 28 November 2016 at 13:23, Sven Van Caekenberghe <[hidden email]> wrote:
> Hi Dimitris,
>
> According to
>
> STCommandLineHandler>>#end
>         | quit  |
>
>         quit := self commandLine hasOption: 'quit'.
>
>         (self commandLine hasOption: 'save')
>                 ifTrue: [ Smalltalk snapshot: true andQuit: quit ].
>
>         quit
>                 ifTrue: [ self exitSuccess ].
>
> You should be able to combine --quit and --save to get the desired effect but I haven't tested it.
>
> BTW, command line usage of Pharo works very well (and has been working well for years).
>
> Sven
>
> > On 28 Nov 2016, at 12:13, Dimitris Chloupis <[hidden email]> wrote:
> >
> > How to execute a script from command line , then save the image and exit ?
> >
> > I use the st command but it offers either --save which saves but keeps image opened or --exit the exits the image without saving
> >
> > ./pharo Ephestos.image st --save  test.st
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Execute a script from command line save image and exit

kilon.alios
In reply to this post by Thierry Goubier


On Mon, Nov 28, 2016 at 3:43 PM Thierry Goubier <[hidden email]> wrote:

if the code is passed as eval it works fine. I assume here is because ! is used to define metadata inside a st file. 

Yes, I'd guess that you are triggering the !! delimited reading when you give a .st. In short, giving a .st file as an argument triggers a FileIn operation, not an execute smalltalk script.

It just happens that FileIn is an executable format (sort of), so you can use it as a script engine until you reach such issues.

Thierry

yeap  and I found the solution a second ! escapes the first one :)

so this strings creates an error 'Hello World!'
but this one works fine 'Hello World!!' and prints
Hello World!

so that problem solved too :)