2

Windows 7 で次の netsh コマンドを実行しようとしていますが、正しくない構文が返されます

Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.system("netsh interface ipv4 set interface ""Conexão de Rede sem Fio"" metric=1")
The syntax of the file name, directory name or volume label is incorrect.


1
>>>

どうしたの?

4

1 に答える 1

4

os.system非常に古い選択であり、実際にはお勧めしません。

代わりに、subprocess.call()またはを検討する必要がありますsubprocess.Popen()

それらの使用方法は次のとおりです。

出力を気にしない場合は、次のようにします。

import subprocess
...
subprocess.call('netsh interface ipv4 set interface ""Wireless Network" metric=1', shell=True)

出力を気にする場合は、次のようにします。

netshcmd=subprocess.Popen('netsh interface ipv4 set interface ""Wireless Network" metric=1', shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE )
output, errors =  netshcmd.communicate()
if errors: 
   print "WARNING: ", errors
 else:
   print "SUCCESS ", output
于 2012-09-12T05:46:23.323 に答える