[Python] Esecuzione dnscmd con python3
Raffaele Salmaso
raffaele a salmaso.org
Lun 21 Ott 2013 15:04:33 CEST
2013/10/21 Marco Passanisi <mpxnet at gmail.com>:
> import subprocess
>
> output = subprocess.Popen('"c:\Windows\system32\dnscmd.exe" ns-01
> /enumzones', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
> out, err = output.communicate()
http://docs.python.org/3.3/library/subprocess.html
"""
args should be a sequence of program arguments or else a single
string. By default, the program to execute is the first item in args
if args is a sequence. If args is a string, the interpretation is
platform-dependent and described below. See the shell and executable
arguments for additional differences from the default behavior. Unless
otherwise stated, it is recommended to pass args as a sequence.
...
On Windows, if args is a sequence, it will be converted to a string in
a manner described in Converting an argument sequence to a string on
Windows. This is because the underlying CreateProcess() operates on
strings.
...
On Windows with shell=True, the COMSPEC environment variable specifies
the default shell. The only time you need to specify shell=True on
Windows is when the command you wish to execute is built into the
shell (e.g. dir or copy). You do not need shell=True to run a batch
file or console-based executable.
"""
hai provato a passare i comandi come una lista di argomenti?
output = subprocess.Popen([ "c:\Windows\system32\dnscmd.exe", "ns-01",
"/enumzones" ], shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
> print(err)
> b'""c:\\Windows\\system32\\dnscmd.exe"" non \x8a riconosciuto come comando
> interno o esterno,\r\n un programma eseguibile o un file batch.\r\n'
ed infatti cerca di eseguire "c:\\Windows\\system32\\dnscmd.exe" che è
diverso da c:\\Windows\\system32\\dnscmd.exe
--
| Raffaele Salmaso
| http://salmaso.org
| https://bitbucket.org/rsalmaso
| http://gnammo.com
Maggiori informazioni sulla lista
Python