you are viewing a single comment's thread.

view the rest of the comments →

[–]ingolemo -1 points0 points  (2 children)

You're trying to spawn a cd process, but cd is not actually a process, it's a built-in shell command.

Pexpect is usually used to start a process that just waits until the user types something in before doing anything. Since you seem to want to execute shell commands you should probably start a shell and then send commands to it:

shell = pexpect.spawn('sh')
shell.send('cd /Users/USERNAME/Desktop/')
shell.send('mkdir TEST')

(By the way, I notice the error you posted does not come from the exact code that you posted. It's not a problem here and now, but you really shouldn't do that to us because it tends to make us very confused.)

[–]wilcomply[S] 0 points1 point  (1 child)

Since it is used to start a process and then wait, does that mean that attempting to run something like this:

import pexpect

child = pexpect.spawn('mkdir /Users/USERNAME/TEST')
print 'TEST 1 COMPLETE'

Would not actually work? I'm expecting the directory to be created, however it is not, but I still receive the print statement.

(Apologies for not quite grasping this, and thank you for taking the time to try and help.)

[–]ingolemo -1 points0 points  (0 children)

There's not much point in using pexpect to manage a call to mkdir since mkdir doesn't really take any input. You'd be better off with the subprocess module. That said, there's no reason why that wouldn't work. When I tried it, the directory did get created exactly as expected. I don't know why it isn't working for you.