About using squeak to script...

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

About using squeak to script...

stéphane ducasse-2
Hi

I would like to use I would like to pass a file as argument, I know  
that this is possible
and I should read the manual. ;) any hints is welcome.

What I do not know is how can I print on stdoutput?
Should I create a primitive (argh) for that?
Would be neat to have that per default (may be this is the time for  
me to learn something new writing
a primitive)

Stef

Reply | Threaded
Open this post in threaded view
|

Re: About using squeak to script...

Lukas Renggli
> I would like to use I would like to pass a file as argument, I know
> that this is possible and I should read the manual. ;) any hints is welcome.

Simply pass the arguments after the image-name, that should work with
the Unix and the Mac VM. By default the image will try to file-in the
first argument (it assumes it is a script), so you probably need to
change that (somewhere in a start-up method) an put your own parse
code in there. The code "SmalltalkImage current extractParameters"
answers a collection of command line parameters.

> What I do not know is how can I print on stdoutput?
> Should I create a primitive (argh) for that?
> Would be neat to have that per default (may be this is the time for
> me to learn something new writing
> a primitive)

As far as I know this only works on the Unix VM with OS Process.

Once I wrote a plugin for Squeak to directly access the Posix
filesystem functions on Unix, because of the bugs with file-access in
Squeak. This also allowed to read and write to stdout, stdin and
stderr by performing the primitives on the file-handles 0, 1 and 2
respectively. I can show you that code if you like.

Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch

Reply | Threaded
Open this post in threaded view
|

Re: About using squeak to script...

stéphane ducasse-2

On 12 août 06, at 11:19, Lukas Renggli wrote:

>> I would like to use I would like to pass a file as argument, I know
>> that this is possible and I should read the manual. ;) any hints  
>> is welcome.
>
> Simply pass the arguments after the image-name, that should work with
> the Unix and the Mac VM. By default the image will try to file-in the
> first argument (it assumes it is a script), so you probably need to
> change that (somewhere in a start-up method) an put your own parse
> code in there. The code "SmalltalkImage current extractParameters"
> answers a collection of command line parameters.
>
>> What I do not know is how can I print on stdoutput?
>> Should I create a primitive (argh) for that?
>> Would be neat to have that per default (may be this is the time for
>> me to learn something new writing
>> a primitive)
>
> As far as I know this only works on the Unix VM with OS Process.
>
> Once I wrote a plugin for Squeak to directly access the Posix
> filesystem functions on Unix, because of the bugs with file-access in
> Squeak. This also allowed to read and write to stdout, stdin and
> stderr by performing the primitives on the file-handles 0, 1 and 2
> respectively. I can show you that code if you like.

Yes I want to see that.
I think that having a StdOut class as in VW is realllllly cool.
This way we can really use squeak to script!


>
> Lukas
>
> --
> Lukas Renggli
> http://www.lukas-renggli.ch
>


Reply | Threaded
Open this post in threaded view
|

Re: Re: About using squeak to script...

Lukas Renggli
> > Once I wrote a plugin for Squeak to directly access the Posix
> > filesystem functions on Unix, because of the bugs with file-access in
> > Squeak. This also allowed to read and write to stdout, stdin and
> > stderr by performing the primitives on the file-handles 0, 1 and 2
> > respectively. I can show you that code if you like.
>
> Yes I want to see that.
> I think that having a StdOut class as in VW is realllllly cool.
> This way we can really use squeak to script!

The problem is, that something like stdout, stdin and stderr does not
exist on all platforms.

Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch

Reply | Threaded
Open this post in threaded view
|

Re: Re: About using squeak to script...

Philippe Marschall
2006/8/12, Lukas Renggli <[hidden email]>:

> > > Once I wrote a plugin for Squeak to directly access the Posix
> > > filesystem functions on Unix, because of the bugs with file-access in
> > > Squeak. This also allowed to read and write to stdout, stdin and
> > > stderr by performing the primitives on the file-handles 0, 1 and 2
> > > respectively. I can show you that code if you like.
> >
> > Yes I want to see that.
> > I think that having a StdOut class as in VW is realllllly cool.
> > This way we can really use squeak to script!
>
> The problem is, that something like stdout, stdin and stderr does not
> exist on all platforms.

So noone should be allowed to use it?

Philippe

Reply | Threaded
Open this post in threaded view
|

Re: About using squeak to script...

Edgar J. De Cleene
Philippe Marschall puso en su mail :

> So noone should be allowed to use it?
>
> Philippe
No,  VM builders should take any advantage what a particular OS / hardware
combination could have.

Off course , the bad news is some Squeakers not have some "advantage"

I wish John let what Sophie VM could be used by regular Squeak.
With his richer fonts set inside, with his several windows, with his only
one archive and all inside (perceived by the user, under of hood the story
is more complex)

Edgar



       
       
               
__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas


Reply | Threaded
Open this post in threaded view
|

Re: Re: About using squeak to script...

David T. Lewis
In reply to this post by Lukas Renggli
On Sat, Aug 12, 2006 at 11:53:37AM +0200, Lukas Renggli wrote:

> >> Once I wrote a plugin for Squeak to directly access the Posix
> >> filesystem functions on Unix, because of the bugs with file-access in
> >> Squeak. This also allowed to read and write to stdout, stdin and
> >> stderr by performing the primitives on the file-handles 0, 1 and 2
> >> respectively. I can show you that code if you like.
> >
> >Yes I want to see that.
> >I think that having a StdOut class as in VW is realllllly cool.
> >This way we can really use squeak to script!
>
> The problem is, that something like stdout, stdin and stderr does not
> exist on all platforms.

OSProcess thisOSProcess stdOut
OSProcess thisOSProcess stdErr
OSProcess thisOSProcess stdErr

This works on Unix/Linux/OS X. It used to work on Windows, but I think
this was broken with some recent security enhancments (sic) to the
Windows VM FilePlugin.

OSProcess is organized such that platform-specific subclasses implement
the OS dependent stuff. It's intended to be extended for any platform.
Likewise for the OSPP plugin, the platform-specific subclasses are
generated for different platforms. Currently this is Unix (which covers
Linux and OS X) and Windows, although the Windows version is not
distributed with VM downloads (rightly so, given that it is no longer
compatible with the security features of the Windows VM).

I'm not necessarily planning to actually do any other platform extensions,
but please feel free to extend it in any way you want. I try to keep
things backward compatible, so you would be fairly safe in doing
your own platform-specific subclasses it you want.

Dave


Reply | Threaded
Open this post in threaded view
|

Re: About using squeak to script...

David T. Lewis
In reply to this post by stéphane ducasse-2
On Sat, Aug 12, 2006 at 10:38:14AM +0200, st?phane ducasse wrote:

> Hi
>
> I would like to use I would like to pass a file as argument, I know  
> that this is possible
> and I should read the manual. ;) any hints is welcome.
>
> What I do not know is how can I print on stdoutput?
> Should I create a primitive (argh) for that?
> Would be neat to have that per default (may be this is the time for  
> me to learn something new writing
> a primitive)
 
Hi Stef,

I'm not sure what you mean by "using Squeak to script", but did you
have in mind something like the following in CommandShell:

script: aScriptString onFailureDo: aBlockWithOneParameter
  "A script is a String containing a list of commands separated
  by Character cr. Evaluate each command in aScriptString until
  a failure is encountered. On failure, answer the result of
  evaluating aBlockWithOneParameter with the last proxy to have
  been evaluated as its parameter. Otherwise, answer the last
  process proxy to have been evaluated."

  "CommandShell new open;
    script: 'who
        help
        ls -l NOSUCHFILE
        help'
    onFailureDo: [:p | 'the proxy that failed was ', p printString]"



Reply | Threaded
Open this post in threaded view
|

Re: Re: About using squeak to script...

David T. Lewis
In reply to this post by David T. Lewis
On Sat, Aug 12, 2006 at 09:47:14AM -0400, David T. Lewis wrote:
> OSProcess thisOSProcess stdOut
> OSProcess thisOSProcess stdErr
> OSProcess thisOSProcess stdErr

Sorry, I meant to say:
  OSProcess thisOSProcess stdOut
  OSProcess thisOSProcess stdErr
  OSProcess thisOSProcess stdIn

On Windows, this would interact with the console:
  OSProcess thisOSProcess openConsole
  OSProcess thisOSProcess closeConsole

Dave


Reply | Threaded
Open this post in threaded view
|

Re: About using squeak to script...

stéphane ducasse-2
In reply to this post by David T. Lewis
For the moment I would like to have the possibility to launch the vm  
with a script and see the results on the command line
like ruby.
So OSProcees seems good for my goal. I will wrap it into Stdoutput to  
have the same as in VW :)
and play with it.

Stef

On 12 août 06, at 15:53, David T. Lewis wrote:

> On Sat, Aug 12, 2006 at 10:38:14AM +0200, st?phane ducasse wrote:
>> Hi
>>
>> I would like to use I would like to pass a file as argument, I know
>> that this is possible
>> and I should read the manual. ;) any hints is welcome.
>>
>> What I do not know is how can I print on stdoutput?
>> Should I create a primitive (argh) for that?
>> Would be neat to have that per default (may be this is the time for
>> me to learn something new writing
>> a primitive)
>
> Hi Stef,
>
> I'm not sure what you mean by "using Squeak to script", but did you
> have in mind something like the following in CommandShell:
>
> script: aScriptString onFailureDo: aBlockWithOneParameter
>   "A script is a String containing a list of commands separated
>   by Character cr. Evaluate each command in aScriptString until
>   a failure is encountered. On failure, answer the result of
>   evaluating aBlockWithOneParameter with the last proxy to have
>   been evaluated as its parameter. Otherwise, answer the last
>   process proxy to have been evaluated."
>
>   "CommandShell new open;
>     script: 'who
>         help
>         ls -l NOSUCHFILE
>         help'
>     onFailureDo: [:p | 'the proxy that failed was ', p printString]"
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: About using squeak to script...

timrowledge

On 12-Aug-06, at 1:29 PM, stéphane ducasse wrote:

> For the moment I would like to have the possibility to launch the  
> vm with a script and see the results on the command line
> like ruby.
But..... we've been able to start the system with a commandline  
argument for a script filename for nearly ten years now. If all you  
need to add is printing some result to stdout and if simply opening  
the file and writing to it won't work then just make a trivial  
stdPlugin.


tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Strange OpCodes: RCM: Randomly Corrupt Microcode



Reply | Threaded
Open this post in threaded view
|

Re: About using squeak to script...

stéphane ducasse-2

On 12 août 06, at 23:42, tim Rowledge wrote:

>
> On 12-Aug-06, at 1:29 PM, stéphane ducasse wrote:
>
>> For the moment I would like to have the possibility to launch the  
>> vm with a script and see the results on the command line
>> like ruby.
> But..... we've been able to start the system with a commandline  
> argument for a script filename for nearly ten years now. If all you  
> need to add is printing some result to stdout and if simply opening  
> the file and writing to it won't work then just make a trivial  
> stdPlugin.

Yes but I do not know how to do it and I think that it would be  
****really**** important to have that per default
and also on most of the platforms.

Stef

>
>
> tim
> --
> tim Rowledge; [hidden email]; http://www.rowledge.org/tim
> Strange OpCodes: RCM: Randomly Corrupt Microcode
>
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: About using squeak to script...

Andreas.Raab
In reply to this post by timrowledge
tim Rowledge wrote:

>
> On 12-Aug-06, at 1:29 PM, stéphane ducasse wrote:
>
>> For the moment I would like to have the possibility to launch the vm
>> with a script and see the results on the command line
>> like ruby.
> But..... we've been able to start the system with a commandline argument
> for a script filename for nearly ten years now. If all you need to add
> is printing some result to stdout and if simply opening the file and
> writing to it won't work then just make a trivial stdPlugin.

What for? Just FFI printf() and friends.

Cheers,
   - Andreas

Reply | Threaded
Open this post in threaded view
|

Re: About using squeak to script...

stéphane ducasse-2

On 15 août 06, at 01:57, Andreas Raab wrote:

> tim Rowledge wrote:
>> On 12-Aug-06, at 1:29 PM, stéphane ducasse wrote:
>>> For the moment I would like to have the possibility to launch the  
>>> vm with a script and see the results on the command line
>>> like ruby.
>> But..... we've been able to start the system with a commandline  
>> argument for a script filename for nearly ten years now. If all  
>> you need to add is printing some result to stdout and if simply  
>> opening the file and writing to it won't work then just make a  
>> trivial stdPlugin.
>
> What for? Just FFI printf() and friends.

How do I do that?

Stef

>
> Cheers,
>   - Andreas
>


Reply | Threaded
Open this post in threaded view
|

Re: About using squeak to script...

Lex Spoon
In reply to this post by stéphane ducasse-2
stéphane ducasse <[hidden email]> writes:
> Yes but I do not know how to do it and I think that it would be
> ****really**** important to have that per default
> and also on most of the platforms.

It would be nice.  While these things might be easy for experienced
people, they are real nuisance for newbies.  Why not go ahead and set
all this up so that new users can Just Do It ?

By the way, another thing you want to do is make errors print stack
traces and compile errors on stdout and/or a log file, when the image
is in script-running mode.  Otherwise, whenever there is an error, the
user will see nothing happen except that Squeak freezes!


-Lex



Reply | Threaded
Open this post in threaded view
|

Re: About using squeak to script...

Andreas.Raab
In reply to this post by stéphane ducasse-2
stéphane ducasse wrote:
>> What for? Just FFI printf() and friends.
>
> How do I do that?

Something like here:

puts: aString
     <cdecl: void 'puts' (char*)>
     ^self externalCallFailed

printf() itself is more complex since it's a varargs call and we don't
support that out of the box.

Cheers,
   - Andreas

Reply | Threaded
Open this post in threaded view
|

Re: About using squeak to script...

stéphane ducasse-2

On 15 août 06, at 19:17, Andreas Raab wrote:

> puts: aString
>     <cdecl: void 'puts' (char*)>
>     ^self externalCallFailed


I tried to compile that in 3.9 but it did not work

I tried

puts: aString
     <cdecl: void 'puts (char*)'>
     ^self externalCallFailed

Bu then should I define a C file and compile it somewhere?

Stef





Reply | Threaded
Open this post in threaded view
|

Re: About using squeak to script...

Andreas.Raab
stéphane ducasse wrote:
>> puts: aString
>>     <cdecl: void 'puts' (char*)>
>>     ^self externalCallFailed
>
> I tried to compile that in 3.9 but it did not work

Needless to say that you *do* need to install the FFI for this to work ;-)

Cheers,
   - Andreas

Reply | Threaded
Open this post in threaded view
|

RE: About using squeak to script...

Ron Teitelbaum
HAHAHAHAH!!!

Ron

> -----Original Message-----
> From: [hidden email] [mailto:squeak-dev-
> [hidden email]] On Behalf Of Andreas Raab
> Sent: Tuesday, August 15, 2006 8:46 PM
> To: The general-purpose Squeak developers list
> Subject: Re: About using squeak to script...
>
> stéphane ducasse wrote:
> >> puts: aString
> >>     <cdecl: void 'puts' (char*)>
> >>     ^self externalCallFailed
> >
> > I tried to compile that in 3.9 but it did not work
>
> Needless to say that you *do* need to install the FFI for this to work ;-)
>
> Cheers,
>    - Andreas
>



Reply | Threaded
Open this post in threaded view
|

Re: About using squeak to script...

stéphane ducasse-2
In reply to this post by Andreas.Raab

On 16 août 06, at 02:46, Andreas Raab wrote:

> stéphane ducasse wrote:
>>> puts: aString
>>>     <cdecl: void 'puts' (char*)>
>>>     ^self externalCallFailed
>> I tried to compile that in 3.9 but it did not work
>
> Needless to say that you *do* need to install the FFI for this to  
> work ;-)

:) indeed I tried in only image where FFI was removed.




12