Login  Register

How to use stdin?

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

How to use stdin?

mirodin

Hey guys,

I tried to use Asciidoctor as converter for my static site generator which I am implementing in python3. Since there is no wrapper module for it, I tried to call Asciidoctor via subprocess. Popen which works quite fine when I give it the filename of my sourcefile.

However I need Asciidoctor to accept a string from my program and tried to use stdin as it was shown in the documentation. Since I never got any results I played a little with the cli and discovered that even the example from the documentation does not work when I run it from bash. Am I doing something wrong since copy&paste from the docs should work (at least that is what I think ;) ).

My python function running Asciidoctor:

def generate_html(filecontent):
    command = ["asciidoctor", "-s", "-o", "-"]
    filecontent = filecontent.encode()
    with Popen(command, stdin=PIPE, stdout=PIPE) as p:
        return p.communicate(input=filecontent)[0]

I am running:

  • Kubuntu 16.04.2
  • Asciidoctor 1.5.5 (installed via apt)

Does anybody know of this and can me help out? If you need any further information I am happy to help.

Cheers,
Tristan

Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: How to use stdin?

mojavelinux
Administrator
The example of the documentation is missing the second `-`. The first `-` goes with the `-o` to say "output to stdout". The second `-` means take from stdin. However, technically you don't need `-o -` in this case since taking from stdin goes to stdout by default.

This should do the trick:

 $ asciidoctor -s -

I'll update the example in the docs.

-Dan

On Thu, Mar 2, 2017 at 1:54 PM, mirodin [via Asciidoctor :: Discussion] <[hidden email]> wrote:

Hey guys,

I tried to use Asciidoctor as converter for my static site generator which I am implementing in python3. Since there is no wrapper module for it, I tried to call Asciidoctor via subprocess. Popen which works quite fine when I give it the filename of my sourcefile.

However I need Asciidoctor to accept a string from my program and tried to use stdin as it was shown in the documentation. Since I never got any results I played a little with the cli and discovered that even the example from the documentation does not work when I run it from bash. Am I doing something wrong since copy&paste from the docs should work (at least that is what I think ;) ).

My python function running Asciidoctor:

def generate_html(filecontent):
    command = ["asciidoctor", "-s", "-o", "-"]
    filecontent = filecontent.encode()
    with Popen(command, stdin=PIPE, stdout=PIPE) as p:
        return p.communicate(input=filecontent)[0]

I am running:

  • Kubuntu 16.04.2
  • Asciidoctor 1.5.5 (installed via apt)

Does anybody know of this and can me help out? If you need any further information I am happy to help.

Cheers,
Tristan




If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/How-to-use-stdin-tp5321.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Dan Allen | @mojavelinux | https://twitter.com/mojavelinux
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: How to use stdin?

mirodin
Hi Dan,

thank you so much for your fast and perfect answer, I really appreciate it.

As I see in the docs you included my use case as well ;)

Cheers,
Tristan
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: How to use stdin?

mojavelinux
Administrator
You're welcome, Tristan!

Cheers,

-Dan

On Fri, Mar 3, 2017 at 5:22 AM, mirodin [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Hi Dan,

thank you so much for your fast and perfect answer, I really appreciate it.

As I see in the docs you included my use case as well ;)

Cheers,
Tristan


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/How-to-use-stdin-tp5321p5325.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Dan Allen | @mojavelinux | https://twitter.com/mojavelinux