2017-08-10 6 views
0

私のpythonプログラムの一部は、サブプロセスを使用してvbsスクリプトを開きます。他のプログラムからのコマンドを使用しようとしているPython 3.6

path = os.sep.join(['C:','Users',getpass.getuser(),'Desktop','Program','build','exe.win32-3.6','vbs.vbs']) 

subprocess.call([sys.executable, path]) 

は、しかし、その代わりに、私のVBSスクリプトを実行するには、Pythonのコードとして、それを実行しようと、私に与えます:NameError:メッセージボックスが定義されていません。 そして、私は手動でvbsスクリプトを実行すると動作します。

私はPythonに通常vbsスクリプトを実行させます。 Pythonコードとして実行しないでください。

+0

だから、正確にあなたの質問は何ですか? –

+0

'sys.executable'はPythonインタープリタです。代わりに '.vbs'ファイルを実行する実行ファイルの名前を使用してください。 – mkrieger1

+0

[Pythonで作成された引数でvbsファイルを実行する]の可能な複製(https://stackoverflow.com/questions/19112944/executing-a-vbs-file-with-arguments-created-by-python) – mkrieger1

答えて

0

sys.executableポイントからシステムのPythonの実行可能ファイルへ。あなたの場合はおそらくC:\Python27\python.exeのようなものでしょう。あなたはそれを印刷して自分で見てください。

VBScriptを実行するには、C:\Windows\system32\wscript.exeを使用します。

さらに、os.path.join()を使用すると、os.sep.join()よりもタスクに適しています。

ですから、で終わるだろう:

system32 = os.path.join(os.environ['SystemRoot'], 'system32') 
wscript = os.path.join(system32, 'wscript.exe') 
path = os.sep.join(['C:','Users',getpass.getuser(),'Desktop','Program','build','exe.win32-3.6','vbs.vbs']) 
subprocess.call([wscript, path]) 
0

これはのサブプロセスに正確に何を伝えているのですか?です。 docs

sys.executable

A string giving the absolute path of the executable binary for the Python interpreter, on systems where this makes sense. If Python is unable to retrieve the real path to its executable, sys.executable will be an empty string or None .

関連する問題