1

I am learning python and am watching the google classes to get started. I have some problems with the 3rd assignment. We are supposed to find special file from a directory and the copy or zip them by giving commands to the command prompt line.

This is what the function that copies files looks like:

def copy(dir,todir):    
    filenames=os.listdir(dir)

    for file in filenames:
       cmd='copy'+' '+file+' '+todir 
       print(cmd)
       (status,output)=subprocess.getstatusoutput(cmd) 
         print(output)
    return

The error says that

'{' not recognized as an internal or external command,operable program or batch file.

The subprocess.getstatusoutput method adds a '{' and a few other things to the cmd before sending it to os.popen().

I am hoping to see a 'x Files copied' as an output.

I am using Windows 8.

Any idea as to what the problem is? Could it be because of the OS? Any idea about how to fix it?

The videos use python2.7 and I am using python3.2 where the command module is replaced by subprocess module. Are the getstatusoutput methods in both the same?

1 Answer 1

1

Documentation says: cmd is actually run as:

{ cmd ; } 2>&1

And the function getstatusoutput() is available on UNIX not on Windows.

Sign up to request clarification or add additional context in comments.

1 Comment

Give a try for the following: process = subprocess.Popen( cmd + params, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=False) and get the output out = process.stdout.read()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.