Pipe with other process

Hi,

I’ve a dos program written by me some times ago, and now I would like to
write a grafic
interface to it with SDL. But I want to write the GUI as a separate
program, now I was
thinking about to run my SDL application and in this launch my program and
make
communication between these 2 process with a redirection of standard
input-output.
So my question are:

  • how can I run my dos program within sdl application?There is some ad’Oc
    command or
    have I to usa something like system()?
  • How can I create a pipe to make my 2 process communicate each other? I
    want to connect
    stdout of one with stdin of the other and viceversa, There is something
    supported by SDL or
    have I to use system call?

Thanks in advance.

E. Dalmasso

Hi,

I’ve a dos program written by me some times ago, and now I would like to
write a grafic
interface to it with SDL. But I want to write the GUI as a separate
program, now I was
thinking about to run my SDL application and in this launch my program and
make
communication between these 2 process with a redirection of standard
input-output.

Since this is 2-way communications it is actually fairly complicated.
In unix you would have
to create a stream pipe, and then fork off a new process (using the
pipe for IPC), dup() the file descriptors, and then run one of the
exec family of system calls.

Since you have a DOS app, I assume you want to do this with MS
Windows, and not a DOS emulator. I am not sure how Windows does it,
but I believe fork() is pretty much unix specific, so it looks to me
like any solution will be OS specific and not portable.

So my question are:

  • how can I run my dos program within sdl application?There is some ad’Oc
    command or
    have I to usa something like system()?

The problem with system() is that your app is no longer in control
when you run it. If your app was something that you could just go run,
and then read the output and process, then that would work fine.

  • How can I create a pipe to make my 2 process communicate each other?
    I want to connect stdout of one with stdin of the other and viceversa,
    There is something supported by SDL or have I to use system call?

I believe you will have to use a few system calls.

Thanks in advance.

Welcome,
ChrisOn Fri, 17 Dec 2004 12:22:08 +0100, emanuele.dalmasso at libero.it <emanuele.dalmasso at libero.it> wrote:


Chris Nystrom
http://www.newio.org/~ccn
AIM: nystromchris

http://home.pacbell.net/theposts/SDLMultiWindows-002.zip

HTH,
JeffOn Friday 17 December 2004 03:22 am, emanuele.dalmasso at libero.it wrote:

I’ve a dos program written by me some times ago, and now I would like to
write a grafic
interface to it with SDL. But I want to write the GUI as a separate
program, now I was
thinking about to run my SDL application and in this launch my program and
make
communication between these 2 process with a redirection of standard
input-output.

— emanuele.dalmasso at libero.it escreveu:

Hi there.

Pipes are OS specific, each OS implements the way and
the logic for it on it own way.
There is another way, wich is using sockets.
Using sockets you have the advantage of portability.
If you want an example, the X Window System works
this way. You just need to take care with the port you
are using (there is a table of the most common-used
ports if you need it) because it can be defined for
other Process / protocol.

You can send a private email if you want suggestions
/ ideas (OS is not the topic of this list)

Hope I helped,

J Inacio Ferrarini
J2EE / J2SE programmer
Extreme Softwares
Salvador - Bahia - Brazil> Hi,

I’ve a dos program written by me some times ago, and
now I would like to
write a grafic
interface to it with SDL. But I want to write the
GUI as a separate
program, now I was
thinking about to run my SDL application and in this
launch my program and
make
communication between these 2 process with a
redirection of standard
input-output.
So my question are:

  • how can I run my dos program within sdl
    application?There is some ad’Oc
    command or
    have I to usa something like system()?
  • How can I create a pipe to make my 2 process
    communicate each other? I
    want to connect
    stdout of one with stdin of the other and viceversa,
    There is something
    supported by SDL or
    have I to use system call?

Thanks in advance.

E. Dalmasso


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Yahoo! Mail - Agora com 250MB de espa?o gratuito. Abra
uma conta agora! http://br.info.mail.yahoo.com/

Hi,

I’ve a dos program written by me some times ago, and now I would like to
write a grafic
interface to it with SDL. But I want to write the GUI as a separate
program, now I was
thinking about to run my SDL application and in this launch my program and
make
communication between these 2 process with a redirection of standard
input-output.
[…]

  • How can I create a pipe to make my 2 process communicate each other? I
    want to connect
    stdout of one with stdin of the other and viceversa, There is something
    supported by SDL or
    have I to use system call?

I’m assuming you don’t want to change or recompile your DOS program.
Otherwise, as J Inacio Ferrarini suggested, sockets (i.e. a TCP/IP
connection) would allow for maximum flexibility.

There are popen() and pclose() calls in stdio.h, which are part of
POSIX.2 (at least according to my Linux man pages ;-). I’ve found that
Windows usually is pretty POSIX-compliant, so these or similar calls
should work. This will, however, only get you stdin OR stdout, but it
may be enough for your purposes.

If you’re not adverse to working with another language, Python
implements slightly more advanced IO piping, see
http://www.python.org/doc/2.3.4/lib/module-popen2.html
which appears to work on both Windows and Unix.
You can either implement your GUI in Python (which has SDL bindings
through http://www.pygame.org/ and OpenGL bindings through
http://pyopengl.sourceforge.net/), or you can write a small Python
controller program which popens (sic) both your DOS and your GUI program
and crosslinks the respective standard in- and outputs. At least in
theory, that is, I’ve never tried it myself.

Hope this helps!
Benjamin

Benjamin Deutsch wrote:

Hi,

I’ve a dos program written by me some times ago, and now I would like to
write a grafic interface to it with SDL. But I want to write the GUI
as a separate
program, now I was thinking about to run my SDL application and in
this launch my program and
make communication between these 2 process with a redirection of
standard
input-output.

[…]

  • How can I create a pipe to make my 2 process communicate each other? I
    want to connect stdout of one with stdin of the other and viceversa,
    There is something
    supported by SDL or have I to use system call?

I’m assuming you don’t want to change or recompile your DOS program.
Otherwise, as J Inacio Ferrarini suggested, sockets (i.e. a TCP/IP
connection) would allow for maximum flexibility.

There are popen() and pclose() calls in stdio.h, which are part of
POSIX.2 (at least according to my Linux man pages ;-). I’ve found that
Windows usually is pretty POSIX-compliant, so these or similar calls
should work. This will, however, only get you stdin OR stdout, but it
may be enough for your purposes.

If you’re not adverse to working with another language, Python
implements slightly more advanced IO piping, see
http://www.python.org/doc/2.3.4/lib/module-popen2.html
which appears to work on both Windows and Unix.
You can either implement your GUI in Python (which has SDL bindings
through http://www.pygame.org/ and OpenGL bindings through
http://pyopengl.sourceforge.net/), or you can write a small Python
controller program which popens (sic) both your DOS and your GUI
program and crosslinks the respective standard in- and outputs. At
least in theory, that is, I’ve never tried it myself.

Hope this helps!
Benjamin

Might I suggest named pipes? You can find them in the MSDN under
Platform SDK->Windows Base Services->Interprocess Communication->Pipes

Thanks to everyones!

Effectively I was thinking to some solutiuon similar to fork() in unix, but that will still work over
other OS, So I was hopefull that SDL implement something.
I’ve never used socket, but from your answer it appear to me to be the best solution
(especially for portability), so I think I’ll go to view documentation about it.

Regards.
E. Dalmasso–

Emanuele Dalmasso
emanuele.dalmasso at theboz.it
http://digilander.libero.it/knightmare

Hi,

Effectively I was thinking to some solutiuon similar to fork() in unix,
but that will still work over other OS, So I was hopefull that SDL
implement something. I’ve never used socket, but from your answer it
appear to me to be the best solution (especially for portability), so I
think I’ll go to view documentation about it.

If You’ll decide to use “client-server-client” thing (ie. based on
sockets), You may want to use SDL_net to make it even more portable
(socket still have some different bits between *nix/windows/BeOS, and
SDL_net handles all of them for You :).

Regards
ahwayakchih