Home > other >  Win the python ospopen () does not perform for help
Win the python ospopen () does not perform for help

Time:09-28

Under the compiler to perform five return
> The import OS
> P=OS. Popen (" ipconfig ")
> P.r eadlines ()
[]


But under the CMD into python has returned home again, how can I solve???

CodePudding user response:

Ipconfig file path problem

CodePudding user response:

Absolute path to try one

CodePudding user response:

I am the path C: \ Windows \ System32 \ ipconfig exe you look for you

CodePudding user response:

Thank you for your reply but the popen is to invoke the command line command not to open the file, why also involves path?

CodePudding user response:

Execute commands, is to open the executable file, ipconfig command is run ipconfig. Exe program files, just in general environment variable configuration in the execution of ipconfig file path, so did not use absolute paths during the CMD command execution to run ipconfig executable files,

CodePudding user response:

> P=OS. Popen (" time ")
> P.r eadlines ()
\ [' xb5 \ xb1 \ xc7 \ xb0 \ xca \ xb1 \ XBC \ xe4:13:22:36. \ n 71 ', '\ xca \ xe4 \ xc8 \ xeb \ xd0 \ xc2 \ xca \ xb1 \ XBC \ xe4:']
Thank you for your reply but also execute commands such as time, is able to carry out, also did not fill in the absolute path,

CodePudding user response:

 
the import the OSP=OS. Popen (" ipconfig ")
Lines=p.r eadlines ()
For the line in lines:
Print (line)


Try this one

CodePudding user response:

Tried or empty return

CodePudding user response:

OS. Popen (command [, mode, bufsize []])
Open a pipe to or from command. The return value is an open file object connected to the pipe, which can be read or written depending on whether mode is 'r' (default) or 'w'. The bufsize argument has the same meaning as the corresponding argument to the built-in open() function. The exit status of the command (encoded in the format specified for wait()) is available as the return value of the close() method of the file object, except that when the exit status is zero (termination without errors), None is returned.

The Availability: Unix, Windows.

Deprecated since version 2.6: This function is obsolete. Use the subprocess module. Check especially the Replacing Older Functions provides with the subprocess module section.

Changed in version 2.0: This function worked unreliably under Windows in earlier versions of Python. This was due to the use of the _popen () function from the libraries provided with Windows. Newer versions of Python do not use the broken implementation from the Windows libraries.

CodePudding user response:

From python2.6 don't recommend using this interface, you can see, you can set the bufsize try, also can see the object returned p printed, what reason be no content,

CodePudding user response:

What I use that method can realize the function I want?

Separate print p is the reality, but it was empty.
> P=OS. Popen (" ipconfig ")
> Print p
& lt; Open the file 'ipconfig' mode 'r' at 0 x036c87b0 & gt;

CodePudding user response:

Now I wonder if my bad win10 64 system support for python!

CodePudding user response:

Thank you friends to solve! Is the demons variable problem, to the path where the CMD in user variables,

> P=OS. Popen (" ipconfig ")
> P.r eadlines ()
['\n', 'Windows IP \xc5\xe4\xd6\xc3\n', '\n', '\n', '\xd2\xd4\xcc\xab\xcd\xf8\xca\xca\xc5\xe4\xc6\xf7 \xd2\xd4\xcc\xab\xcd\xf8:\n', '\n', ' \xc1\xac\xbd\xd3\xcc\xd8\xb6\xa8\xb5\xc4 DNS \xba\xf3\xd7\xba . . . . . . . : \n', ' \xb1\xbe\xb5\xd8\xc1\xb4\xbd\xd3 IPv6 \xb5\xd8\xd6\xb7. . . . . . . . : fe80::9d67:8487:6d93:f302%14\n', ' IPv4 \xb5\xd8\xd6\xb7 . . . . . . . . . . . . : 172.18.116.78\n', ' \xd7\xd3\xcd\xf8\xd1\xda\xc2\xeb . . . . . . . . . . . . : 255.255.255.0\n', ' \xc4\xac\xc8\xcf\xcd\xf8\xb9\xd8. . . . . . . . . . . . . : 172.18.116.254\n', '\n', '\xd2\xd4\xcc\xab\xcd\xf8\xca\xca\xc5\xe4\xc6\xf7 \xd2\xd4\xcc\xab\xcd\xf8 2:\n', '\n', ' \xc1\xac\xbd\xd3\xcc\xd8\xb6\xa8\xb5\xc4 DNS \xba\xf3\xd7\xba . . . . . . . : \n', ' \xb1\xbe\xb5\xd8\xc1\xb4\xbd\xd3 IPv6 \xb5\xd8\xd6\xb7. . . . . . . . : fe80::39f5:3175:aaff:d7e0%13\n', ' IPv4 \xb5\xd8\xd6\xb7 . . . . . . . . . . . . : 192.168.213.1\n', ' \xd7\xd3\xcd\xf8\xd1\xda\xc2\xeb . . . . . . . . . . . . : 255.255.255.0\n', ' \xc4\xac\xc8\xcf\xcd\xf8\xb9\xd8. . . . . . . . . . . . . : \n', '\n', '\xd2\xd4\xcc\xab\xcd\xf8\xca\xca\xc5\xe4\xc6\xf7 \xd2\xd4\xcc\xab\xcd\xf8 3:\n', '\n', ' \xc1\xac\xbd\xd3\xcc\xd8\xb6\xa8\xb5\xc4 DNS \xba\xf3\xd7\xba . . . . . . . : \n', ' \xb1\xbe\xb5\xd8\xc1\xb4\xbd\xd3 IPv6 \xb5\xd8\xd6\xb7. . . . . . . . : fe80::c19f:b619:d9e6:6731%8\n', ' IPv4 \xb5\xd8\xd6\xb7 . . . . . . . . . . . . : 192.168.182.1\n', ' \xd7\xd3\xcd\xf8\xd1\xda\xc2\xeb . . . . . . . . . . . . : 255.255.255.0\n', ' \xc4\xac\xc8\xcf\xcd\xf8\xb9\xd8. . . . . . . . . . . . . : \n']

CodePudding user response:

Thank you friends to solve! Is the demons variable problem, to the path where the CMD in user variables,
This is how to solve, you for help
  • Related