Note that there are some explanatory texts on larger screens.

plurals
  1. POPython: subprocess.stdin.write is not working properly
    primarykey
    data
    text
    <p>I'm new to python but I can code and debug a bit. The following problem has been on my head for the past couple of days and looking out for an answer. Any help is much appreciated. Task: I wanted to do an interactive telnet (I know there is an telnet library, but we are not using it for various reasons). For this purpose, I use a subprocess.popen</p> <pre><code>p = subprocess.Popen(telnet_command, stdin = subprocess.PIPE, stdout = outputfileobj, stderr = errorfileobj) </code></pre> <p>I do a poll() to see if the server has got connected to the session. Once I verified, I proceed to write to the stdin for interactive communication.</p> <pre><code>inputTxt = 'GET / HTTP/1.1\nHost: ' + hostheader + '\n\n' p.stdin.write(inputTxt) p.stdin.flush() </code></pre> <p>Here is where the problem has occurred. I get the http response (or atleast output) for 5/6 times but 1/6 time, I do not get a output and the subprocess gets terminated - which is not possible.</p> <p>I ran a system trace for the failure case and please find below the same.</p> <pre><code>16129 write(7, "GET / HTTP/1.1\nHost: www.google."..., 37) = 37 16129 gettimeofday({1310538497, 134474}, NULL) = 0 16129 futex(0x81993a8, FUTEX_WAKE, 1) = 0 16129 stat64("/etc/localtime", {st_mode=S_IFREG|0644, st_size=56, ...}) = 0 16129 fstat64(4, {st_mode=S_IFREG|0644, st_size=520689, ...}) = 0 16129 _llseek(4, 520689, [520689], SEEK_SET) = 0 16129 stat64("/etc/localtime", {st_mode=S_IFREG|0644, st_size=56, ...}) = 0 16129 write(4, "2011-07-13 06:28:17,134 : pconns"..., 170) = 170 16129 futex(0x81d3b30, FUTEX_WAKE, 1) = 0 16129 waitpid(16198, 0xffa945e8, WNOHANG) = 0 16129 gettimeofday({1310538497, 135160}, NULL) = 0 16129 fstat64(6, {st_mode=S_IFREG|0644, st_size=81, ...}) = 0 16129 fstat64(6, {st_mode=S_IFREG|0644, st_size=81, ...}) = 0 16129 mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xf74b9000 16129 _llseek(6, 0, [0], SEEK_SET) = 0 16129 fstat64(6, {st_mode=S_IFREG|0644, st_size=81, ...}) = 0 16129 _llseek(6, 0, [0], SEEK_CUR) = 0 16129 read(6, "Trying 74.125.236.48...\nConnecte"..., 4096) = 81 16129 read(6, "", 4096) = 0 16129 close(6) = 0 16129 munmap(0xf74b9000, 4096) = 0 16129 gettimeofday({1310538497, 135778}, NULL) = 0 16129 futex(0x81993a8, FUTEX_WAKE, 1) = 0 16198 &lt;... select resumed&gt; ) = 1 (in [0]) 16198 read(0, "GET / HTTP/1.1\nHost: www.google."..., 8191) = 37 16129 stat64("/etc/localtime", &lt;unfinished ...&gt; 16198 ioctl(1, TCFLSH, 0) = -1 ENOTTY (Inappropriate ioctl for device) 16129 &lt;... stat64 resumed&gt; {st_mode=S_IFREG|0644, st_size=56, ...}) = 0 16198 select(4, [0 3], [3], [3], {0, 0}) = 1 (out [3], left {0, 0}) 16129 fstat64(4, {st_mode=S_IFREG|0644, st_size=520859, ...}) = 0 16198 send(3, "GET / HTTP/1.1\r\nHos\377\363\377\375\6", 24, 0 &lt;unfinished ...&gt; 16129 _llseek(4, 520859, &lt;unfinished ...&gt; 16198 &lt;... send resumed&gt; ) = 24 16198 select(4, [0 3], [3], [3], {0, 0} &lt;unfinished ...&gt; 16129 &lt;... _llseek resumed&gt; [520859], SEEK_SET) = 0 16198 &lt;... select resumed&gt; ) = 1 (out [3], left {0, 0}) 16198 send(3, ": www.google.com\r\n\r\n", 20, 0 &lt;unfinished ...&gt; 16129 stat64("/etc/localtime", &lt;unfinished ...&gt; 16198 &lt;... send resumed&gt; ) = 20 </code></pre> <p>If you closely look at the line <b>16198 send(3, "GET / HTTP/1.1\r\nHos\377\363\377\375\6", 24, 0 </b> in the trace, the string "Hos<b>t</b>" is replaced by some "Hos<b>\377\363\377\375\6</b>". I'm not sure why this occurs once in a while and also this closes the telnet connection I established. Please let me know if you need more data.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload