hi

I have a problem with the following code ...

>>> j = win32pipe.popen('c:\\disk\\plink -pw mat123 df -g','r')
>>> for i in j:
print i


>>>
As you can see the file object 'j' does not have anything in it...
But if I type 'c:\disk\plink -pw ibm123 df -g' in the DOS prompt, it works fine and gives me the required result...

So I gave a simple command via python like this...

>>> j = win32pipe.popen('dir','r')
>>> for i in j:
print i

Volume in drive C is DRIVE-C
Volume Serial Number is 5C8D-1DAC

Directory of C:\Disk

29/06/06 03:28 PM <DIR> .
29/06/06 03:28 PM <DIR> ..
29/06/06 02:11 PM <DIR> .idlerc
06/06/06 11:29 AM 225,280 1suntemplate.xls
29/06/06 03:28 PM 14,848 29-6-2006.xls
.
.
19 File(s) 1,474,430 bytes
3 Dir(s) 27,306,981,376 bytes free

>>>
It works fine... but not the previous command....
But the same code executes perfectly on a different machine... Both have XP...

Can anybody help me ??? Why the same code is working on one machine & not in another???

Dani AI

Generated

Quick summary of likely causes and practical fixes tied to the thread: sees no output when launching plink via win32pipe.popen on one XP box while the same command works elsewhere. Suggestions already posted touch the right areas: quoting/path issues (), pipe reliability (), and the observation that plink can fail when it has no usable stdin (). The problem is usually not “mystical XP” but one of these: the child process expects a console or readable stdin, the command is being parsed differently by the shell, or the process is being spawned with handles that plink cannot use.

Concrete troubleshooting checklist

  • Verify the same plink.exe and same command line on both machines (full path and extension). Differences in versions or antivirus/firewall behavior can change runtime behavior.
  • Check whether simple programs that write to stdout work under the same popen call (to separate pipe/pywin32 issues from plink-specific behavior).
  • Prefer launching plink without relying on a shell parser (pass argv as a list) and ensure stdin is a valid handle so plink does not block or error trying to read from the console.

Practical, modern Python approach (works around programs that read stdin)

import subprocess
cmd = ["C:\\path\\to\\plink.exe", "user@host", "-pw", "yourpassword", "df", "-g"]
with open("NUL", "r") as devnull:                       # cross-version way to give a valid stdin
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=devnull)
    out, err = p.communicate()
print(out.decode('utf-8', 'replace'))
if err:
    print(err.decode('utf-8', 'replace'))

Additional notes: try plink’s non-interactive/batch option if available (so it won’t prompt), avoid passing sensitive passwords on command lines when possible, and compare pywin32/subsystem/permissions between the two machines. These steps isolate whether the issue is plink refusing a missing stdin, a quoting/shell problem, or a platform-specific pipe-inheritance quirk.

Recommended Answers

All 5 Replies

Could be different level of XP upgrade. Early version of Window XP quite buggy!

win32pipes are broken by definition, unfortunately. They won't work in all cases. I'd post a question to comp.lang.python (http://groups.google.com/group/comp.lang.python) where someone else should have experience working with/around plink specifically.

Maybe using the famous Microsoft kludge for handling spaces in filenames will do the trick. This wraps a pair of single quotes and double quote around the string. Try:

j = win32pipe.popen('"c:\\disk\\plink jnitin@10.94.101.178 -pw mat123 df -g"','r')

Also, if plink is plink.exe use extension.

Thanks for the feedback .... Its probably due to XP, the code works fine with Win2K...

I managed to work around this problem adding this at the end of the command: "2>&1 0< nul:"

plink refuses to work without stdin redirected. It fails with the following error:

Unable to read from standard input: Invalid Identificator.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.