python - pexpect for terminal at local computer -


i developing codes user interaction using pexpect local terminal on mac (not remote ssh) instead of using subprocess. don't know did wrong following cases receive empty outputs:

1)

child = pexpect.spawn('ls') child.expect(pexpect.eof) output = child.before print output 

the output empty

2)

child = pexpect.spawn('ls -l') child.expect(pexpect.eof) output = child.before print output 

it works well. output list of files , folder type ls -l @ local terminal

3)

child = pexpect.spawn('pwd') child.expect(pexpect.eof) output = child.before print output 

the output empty

the output must existing, not empty in 3 cases right? know why 'ls' , 'pwd' empty, 'ls -l' not? should fix 'empty' output?

best regards, quyen tran

for running commands not require interaction, spawn not right method. better use pexpect.run method , output return value.

pexpect.spawn more suited spawn child process need send commands , expect response. code works fine on terminal if aren't able done on yours, use run method

child = pexpect.spawn('ls') child.expect(pexpect.eof) 0 print child.before codes program.c << output of ls command 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -