「コマンド」モードでソフトウェアを実行するサブプロセスを実行しています。(このソフトウェアは The Foundy の Nuke です。そのソフトウェアを知っている場合)
コマンドモードでは、このソフトウェアはユーザー入力を待っています。このモードでは、UI なしで合成スクリプトを作成できます。
プロセスを開始するこのコードを実行し、アプリケーションの開始が完了したことを確認してから、プロセスにいくつかのコマンドを送信しようとしましたが、stdin がコマンドを適切に送信していないようです。
このプロセスをテストするために行ったサンプル コードを次に示します。
import subprocess
appPath = '/Applications/Nuke6.3v3/Nuke6.3v3.app/Nuke6.3v3' readyForCommand = False
commandAndArgs = [appPath, '-V', '-t']
commandAndArgs = ' '.join(commandAndArgs)
process = subprocess.Popen(commandAndArgs,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=True, )
while True:
if readyForCommand:
print 'trying to send command to nuke...'
process.stdin.write('import nuke')
process.stdin.write('print nuke')
process.stdin.write('quit()')
print 'done sending commands'
readyForCommand = False
else:
print 'Reading stdout ...'
outLine = process.stdout.readline().rstrip()
if outLine:
print 'stdout:', outLine
if outLine.endswith('getenv.tcl'):
print 'setting ready for command'
readyForCommand = True
if outLine == '' and process.poll() != None:
print 'in break!'
break
print('return code: %d' % process.returncode)
シェルで nuke を実行し、同じコマンドを送信すると、次のようになります。
sylvain.berger core/$ nuke -V -t
[...]
Loading /Applications/Nuke6.3v3/Nuke6.3v3.app/Contents/MacOS/plugins/getenv.tcl
>>> import nuke
>>> print nuke
<module 'nuke' from '/Applications/Nuke6.3v3/Nuke6.3v3.app/Contents/MacOS/plugins/nuke/__init__.pyc'>
>>> quit()
sylvain.berger core/$
標準入力がコマンドを適切に送信していない理由は何ですか? ありがとう