I'm trying to call markdown as an external process

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

I'm trying to call markdown as an external process

patmaddox
I'm trying to do something which (I think) is very simple: I just want to run a line of text through Markdown and get the output.

I've spent all day reading through the code for OSProcess and CommandShell.  It took me a while, but I finally figured out I can run a command and get its output with:

UnixProcess waitForCommandOutput: 'ls ~'

The next problem I'm having is getting markdown to run on an arbitrary string.  If I go into my shell and do:

$ /usr/local/bin/markdown <<END
> # This is a heading
> This is a paragraph with _emphasis_
> END
<h1>This is a heading</h1>

Then I get the output that I expect:
<p>This is a paragraph with <em>emphasis</em></p>

I can't figure out how to do this with OSProcess though.  I've tried:

UnixProcess waitForCommand: ('/usr/local/bin/markdown <<END
hello world
END')

but with no luck.  I've also tried using OSProcess at a lower level, setting up the stream input object, but it seems to require a reference to an actual file, rather than just a stream.

Anyone have any ideas?  I want to take an arbitrary string and use that as the input to my markdown command, and then store that output in an instance variable.  I could use some help.

Thanks,
Pat

_______________________________________________
Pharo-users mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users
Reply | Threaded
Open this post in threaded view
|

Re: I'm trying to call markdown as an external process

patmaddox
On Oct 5, 2010, at 5:05 PM, Pat Maddox wrote:

> I'm trying to do something which (I think) is very simple: I just want to run a line of text through Markdown and get the output.
>
> I've spent all day reading through the code for OSProcess and CommandShell.  It took me a while, but I finally figured out I can run a command and get its output with:
>
> UnixProcess waitForCommandOutput: 'ls ~'
>
> The next problem I'm having is getting markdown to run on an arbitrary string.  If I go into my shell and do:
>
> $ /usr/local/bin/markdown <<END
>> # This is a heading
>> This is a paragraph with _emphasis_
>> END
> <h1>This is a heading</h1>
>
> Then I get the output that I expect:
> <p>This is a paragraph with <em>emphasis</em></p>
>
> I can't figure out how to do this with OSProcess though.  I've tried:
>
> UnixProcess waitForCommand: ('/usr/local/bin/markdown <<END
> hello world
> END')
>
> but with no luck.  I've also tried using OSProcess at a lower level, setting up the stream input object, but it seems to require a reference to an actual file, rather than just a stream.
>
> Anyone have any ideas?  I want to take an arbitrary string and use that as the input to my markdown command, and then store that output in an instance variable.  I could use some help.
>
> Thanks,
> Pat

Okay I've got something which appears to work fine.

(OSProcess thisOSProcess command: '/usr/local/bin/markdown' input: '#this is a heading
this is a paragraph _with emphasis_') output

Kind of a painful day, but glad to be moving on :)

Pat

_______________________________________________
Pharo-users mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users
Reply | Threaded
Open this post in threaded view
|

Re: I'm trying to call markdown as an external process

Mariano Martinez Peck
David may help you.

Cheers

Mariano

On Wed, Oct 6, 2010 at 2:27 AM, Pat Maddox <[hidden email]> wrote:
On Oct 5, 2010, at 5:05 PM, Pat Maddox wrote:

> I'm trying to do something which (I think) is very simple: I just want to run a line of text through Markdown and get the output.
>
> I've spent all day reading through the code for OSProcess and CommandShell.  It took me a while, but I finally figured out I can run a command and get its output with:
>
> UnixProcess waitForCommandOutput: 'ls ~'
>
> The next problem I'm having is getting markdown to run on an arbitrary string.  If I go into my shell and do:
>
> $ /usr/local/bin/markdown <<END
>> # This is a heading
>> This is a paragraph with _emphasis_
>> END
> <h1>This is a heading</h1>
>
> Then I get the output that I expect:
> <p>This is a paragraph with <em>emphasis</em></p>
>
> I can't figure out how to do this with OSProcess though.  I've tried:
>
> UnixProcess waitForCommand: ('/usr/local/bin/markdown <<END
> hello world
> END')
>
> but with no luck.  I've also tried using OSProcess at a lower level, setting up the stream input object, but it seems to require a reference to an actual file, rather than just a stream.
>
> Anyone have any ideas?  I want to take an arbitrary string and use that as the input to my markdown command, and then store that output in an instance variable.  I could use some help.
>
> Thanks,
> Pat

Okay I've got something which appears to work fine.

(OSProcess thisOSProcess command: '/usr/local/bin/markdown' input: '#this is a heading
this is a paragraph _with emphasis_') output

Kind of a painful day, but glad to be moving on :)

Pat

_______________________________________________
Pharo-users mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users


_______________________________________________
Pharo-users mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users
Reply | Threaded
Open this post in threaded view
|

Re: I'm trying to call markdown as an external process

David T. Lewis
Hi Pat,

I'm not familiar with Markdown, but it sounds like you want to run
an external process (Markdown), write to its standard input from Smalltalk,
and read its standard input back into Smalltalk.

Try using class PipeableOSProcess for this. There are some examples
in the class side methods that show how it works. PipeableOSProcess
works at a higher level than the classes in OSProcess, and it will
handle the issues of connecting the external process to your image
through pipes.

Be careful about reading the output from your external Markdown
process. Pipes by default work in blocking mode, see #setNonblocking
to change this. If you do a read on the output of a blocking pipe,
and if there is no data available, your VM will block and your
image will be locked up. So save your image frequently until you
get the details worked out ;)

HTH,
Dave


On Thu, Oct 07, 2010 at 01:00:24AM +0200, Mariano Martinez Peck wrote:

> David may help you.
>
> Cheers
>
> Mariano
>
> On Wed, Oct 6, 2010 at 2:27 AM, Pat Maddox <[hidden email]> wrote:
>
> > On Oct 5, 2010, at 5:05 PM, Pat Maddox wrote:
> >
> > > I'm trying to do something which (I think) is very simple: I just want to
> > run a line of text through Markdown and get the output.
> > >
> > > I've spent all day reading through the code for OSProcess and
> > CommandShell.  It took me a while, but I finally figured out I can run a
> > command and get its output with:
> > >
> > > UnixProcess waitForCommandOutput: 'ls ~'
> > >
> > > The next problem I'm having is getting markdown to run on an arbitrary
> > string.  If I go into my shell and do:
> > >
> > > $ /usr/local/bin/markdown <<END
> > >> # This is a heading
> > >> This is a paragraph with _emphasis_
> > >> END
> > > <h1>This is a heading</h1>
> > >
> > > Then I get the output that I expect:
> > > <p>This is a paragraph with <em>emphasis</em></p>
> > >
> > > I can't figure out how to do this with OSProcess though.  I've tried:
> > >
> > > UnixProcess waitForCommand: ('/usr/local/bin/markdown <<END
> > > hello world
> > > END')
> > >
> > > but with no luck.  I've also tried using OSProcess at a lower level,
> > setting up the stream input object, but it seems to require a reference to
> > an actual file, rather than just a stream.
> > >
> > > Anyone have any ideas?  I want to take an arbitrary string and use that
> > as the input to my markdown command, and then store that output in an
> > instance variable.  I could use some help.
> > >
> > > Thanks,
> > > Pat
> >
> > Okay I've got something which appears to work fine.
> >
> > (OSProcess thisOSProcess command: '/usr/local/bin/markdown' input: '#this
> > is a heading
> > this is a paragraph _with emphasis_') output
> >
> > Kind of a painful day, but glad to be moving on :)
> >
> > Pat
> >
> > _______________________________________________
> > Pharo-users mailing list
> > [hidden email]
> > http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users
> >

_______________________________________________
Pharo-users mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users