FAQ
I can't get this to work:

# commer.py - to test communication with other process
from popen2 import popen2
(child_stdout, child_stdin) = popen2("commer.exe")
print "Got here 1"
line = child_stdout.readline()
print "Got here 2"
child_stdin.write(line)
child_stdin.close
child_stdout.close

The compile C program, commer.exe, writes a line of text to its stdout.
The python program does not receive it; it never gets to print "Got here
2". Commer.exe does begin execution. Here's commer.c, but there
appears to be no problem with it. Commer.exe can be executed alone, and
it behaves as expected.

/* commer.c - to test communication with other process */
/* this program will output a line of text to stdout, and then
accept a line of input from stdin.
It also creates a text file called out.txt and writes to it.
*/
#include <stdio.h>
#include <stdlib.h>
int main() {
char line[] = "A line of text-----------------------------";
FILE *outfile;
/* Record that execution began: */
outfile = fopen("out.txt", "w");
fprintf(outfile, "commer.exe starting up.\n");
fclose(outfile);
/* Output a line of text to stdout: */
printf("%s\n", line);
/* Record that that happened: */
outfile = fopen("out.txt", "a");
fprintf(outfile, "text line was output to stdout\n");
fclose(outfile);
/* Get a line of text from stdin: */
scanf("%s", line);
/* Record the result: */
outfile = fopen("out.txt", "a");
fprintf(outfile,"%s was received.\n", line);
fclose(outfile);
return 0;
}

Thanks,

Mitchell Timin

--
I'm proud of http://ANNEvolve.sourceforge.net. I'm currently working on a
major update of the SailChallenge package. If you want to write software,
or articles, or do testing for ANNEvolve, let me know.

Humans may know that my email address is: (but remove the number)
zenguy at shaw789 dot ca.

Search Discussions

  • Rene Pijlman at Mar 28, 2006 at 6:36 pm
    I. Myself:
    I can't get this to work
    With what versions of what software on what platform?

    --
    Ren? Pijlman
  • I. Myself at Mar 28, 2006 at 7:27 pm

    Rene Pijlman wrote:
    I. Myself:
    I can't get this to work
    With what versions of what software on what platform?
    I'm glad you asked. really!

    Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32

    Windows 2000. AMD processor. mingw compiler.

    Mitchell Timin

    --
    I'm proud of http://ANNEvolve.sourceforge.net. I'm currently working on a
    major update of the SailChallenge package. If you want to write software,
    or articles, or do testing for ANNEvolve, let me know.

    Humans may know that my email address is zenguy at shaw dot ca.




    From http Tue Mar 28 21:30:05 2006
    From: http (Paul Rubin)
    Date: 28 Mar 2006 11:30:05 -0800
    Subject: No Cookie: how to implement session?
    References: <1143567624.164865.71730@v46g2000cwv.googlegroups.com>
    <9uvi225dlg8kd892jpfg8mqne6chnavus6@4ax.com>
    Message-ID: <7xbqvqnz9e.fsf@ruckus.brouhaha.com>

    Dennis Lee Bieber <wlfraed at ix.netcom.com> writes:
    Yes... And watch them flounder on sites that use cookies /for/ a
    form of security (ie, those sites that require logins...) Cookies can be
    set to expire, so the "session" can time-out... whereas...
    Sites should never rely on cookies timing out. If there's any
    security concern about session persistence and you don't want to track
    the session timeout on the server, then encode an expiration time into
    the cookie itself, and cryptographically authenticate the cookie.
    I tried to add hidden field with a sessionID in every python CGI script
    generated web pages, so everytime my client POST a request, the server
    The trouble here is that it stops internal links (retrieved with GET
    rather than POST) from working. So normally what you're describing is
    done with session ID's in the url (see amazon.com for example). That,
    too, isn't so great for security, especially for ecommerce sites,
    since people tend to share url's with their friends. E.g., they'll
    post to Usenet or web bbs's, So-and-so is offering a great deal on
    Python manuals, the url is <http://whatever...> where "whatever"
    includes the session ID. Anyone clicking the url then ends up with
    the same shopping cart as the person who posted it.

    To OP: keep in mind also that anyone who disables cookies probably
    also disables javascript, so relying on javascript as you described
    for redirection doesn't work too well either.
  • I. Myself at Mar 28, 2006 at 8:07 pm

    Dennis Lee Bieber wrote:
    On Tue, 28 Mar 2006 18:02:46 GMT, "I. Myself" <No.Spam at Spam.none>
    declaimed the following in comp.lang.python:

    The compile C program, commer.exe, writes a line of text to its stdout.
    The python program does not receive it; it never gets to print "Got here
    2". Commer.exe does begin execution. Here's commer.c, but there
    appears to be no problem with it. Commer.exe can be executed alone, and
    it behaves as expected.
    Try flushing stdout... Many C runtimes detect when stdout is not a
    console and go to a buffered output mode; without a flush, it may be
    holding data until a (disk) block is filled...
    That worked! I put fflush(stdout); after the printf() statement,
    and that fixed it.

    Thanks!

    Mitchell Timin

    I'm proud of http://ANNEvolve.sourceforge.net. I'm currently working on a
    major update of the SailChallenge package. If you want to write software,
    or articles, or do testing for ANNEvolve, let me know.

    Humans may know that my email address is zenguy at shaw789 dot ca.
    (Remove the 3-digit number.)

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedMar 28, '06 at 6:02p
activeMar 28, '06 at 8:07p
posts4
users2
websitepython.org

2 users in discussion

I. Myself: 3 posts Rene Pijlman: 1 post

People

Translate

site design / logo © 2022 Grokbase