simple question, but I am stuck. 
Author Message
 simple question, but I am stuck.

Hi All,
          I am trying to work out how to "PIPE" data into an external
program.  I am familiar with the system("commandhere") command but I
would like to know how to execute "|command"  (and pipe data into it).

example - from the BASH shell,

"cat test.ps | gs -sDEVICE=pdfwrite -sOutputFile=- -q -"

will out-put the resulting file (pdf) into stdout.

Instead of having to first write the data to "test.ps" I would like to
be able to pipe directly into gs from my C program.

Any (and all) help appreciated.

Many Thanks,
                    Andrew Donehue.



Thu, 03 Jun 2004 01:04:40 GMT  
 simple question, but I am stuck.


Quote:
> Hi All,
>           I am trying to work out how to "PIPE" data into an external
> program.  I am familiar with the system("commandhere") command but I
> would like to know how to execute "|command"  (and pipe data into it).

> example - from the BASH shell,

> "cat test.ps | gs -sDEVICE=pdfwrite -sOutputFile=- -q -"

> will out-put the resulting file (pdf) into stdout.

<OT>

Wouldn't
gs -sDEVICE=pdfwrite -sOutputFile=- -q - < test.ps

also work?
</OT>

Quote:

> Instead of having to first write the data to "test.ps" I would like to
> be able to pipe directly into gs from my C program.

> Any (and all) help appreciated.

> Many Thanks,
>                     Andrew Donehue.

Here's a hint:

C has three streams open at the beginning of your program: stdin, stdout,
and stderr.  You can use them to do rudimentary piping.

Oh, you mean send data to an external program?  Some versions of C (most
notably BSD versions) have popen() and pclose() as extensions.  Others are
encouraged to fake it with some combination of pipe(), fdopen(), fork(),
system(), wait() (all from POSIX except system(), which is standard), or the
stdio functions.  But there really isn't anything that's in the ANSI
standard short of dumping all your data to a file and then calling system()
when the file's closed.

Gregory Pietsch



Thu, 03 Jun 2004 01:51:36 GMT  
 simple question, but I am stuck.

Quote:

> Hi All,
>           I am trying to work out how to "PIPE" data into an external
> program.  I am familiar with the system("commandhere") command but I
> would like to know how to execute "|command"  (and pipe data into it).

> example - from the BASH shell,

> "cat test.ps | gs -sDEVICE=pdfwrite -sOutputFile=- -q -"

> will out-put the resulting file (pdf) into stdout.

> Instead of having to first write the data to "test.ps" I would like to
> be able to pipe directly into gs from my C program.

Functions for piping are not part of the standard library so your
question
is off-topic in this ng.

But you can do this quite simply: have your program write to stdout
instead of
a file and then pipe from the command line:-

  "yourprogram | gs -sDEVICE=pdfwrite -sOutputFile=- -q -"

You can still use it to write a file when required:

  "yourprogram > test.ps"

Malcolm Kay



Thu, 03 Jun 2004 21:59:26 GMT  
 simple question, but I am stuck.


Quote:
>Hi All,
>          I am trying to work out how to "PIPE" data into an external
>program.  I am familiar with the system("commandhere") command but I
>would like to know how to execute "|command"  (and pipe data into it).

>example - from the BASH shell,

>"cat test.ps | gs -sDEVICE=pdfwrite -sOutputFile=- -q -"

>will out-put the resulting file (pdf) into stdout.

>Instead of having to first write the data to "test.ps" I would like to
>be able to pipe directly into gs from my C program.

>Any (and all) help appreciated.

You can't do this in standard C. However Unix/POSIX defines ways to do
it.  See comp.unix.pogrammer for more information.

--
-----------------------------------------


-----------------------------------------



Thu, 03 Jun 2004 07:49:05 GMT  
 simple question, but I am stuck.
Quote:



> >          I am trying to work out how to "PIPE" data into an external
> >program.  I am familiar with the system("commandhere") command but I
> >would like to know how to execute "|command"  (and pipe data into it).

... snip ...

> You can't do this in standard C. However Unix/POSIX defines ways to do
> it.  See comp.unix.pogrammer for more information.

                  ___^^^^^^^^^
They are having a pogrom against OT posters.

--

   Available for consulting/temporary embedded and systems.
   (Remove "XXXX" from reply address. yahoo works unmodified)



Fri, 04 Jun 2004 06:43:54 GMT  
 simple question, but I am stuck.


...

Quote:
>C has three streams open at the beginning of your program: stdin, stdout,
>and stderr.  You can use them to do rudimentary piping.

>Oh, you mean send data to an external program?  Some versions of C (most
>notably BSD versions) have popen() and pclose() as extensions.

These are POSIX defined function that all UNIX systems must have. See
comp.unix.programmer for more details.

--
-----------------------------------------


-----------------------------------------



Fri, 04 Jun 2004 20:12:35 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. I'm stuck with ArrayList (simple question)

2. Simple Question I am sure !!!!!

3. I am completely stuck!

4. Urgently help as i am stuck!

5. Help I am stuck!!!!!!!!!!!!

6. I am stuck with VC optimization.

7. Help, I am stuck in AssertValid hell

8. I am stuck in FULL screen view.

9. I am a retard (perhaps a simple problem??)

10. a very simple problem about # include files but i am a beginer

11. a simple simple question...

12. simple simple print question

 

 
Powered by phpBB® Forum Software