Running a program with arguments

I'm trying to run a program using a python program. The program is supposed to run the program, get the output, and write it to a text file. The program being run (which is an exe), takes one argument, so I used:

subprocess.call(["path", "arg"])

This works fine, but the problem is when I write it to the file I get:

TypeError: argument 1 must be string or read-only character buffer, not int

I tried:

str(subprocess.call(["path", "arg"]))

Theres no error with this, but it only writes zero to the text file, not the real output of the program. Is there any way to either convert the output to a string or another command where it already is string?

I don't know what that "it" is you are trying to write to the file. You seem to want to write the output of the program being run, but I don't think you can do that with .call() which just returns the final status of the program run, which is an integer and needs to be converted to a string to write out, but that's not what you really wanted anyway...

Basically, It opens the file where the final hash will be stored, then sets the variable code equal to the output of the program, then writes it to a file. md5.exe is the program I'm using which is in the same directory as the python file. -d is the command used to hash, and whatever comes after that is what will be hashed. Right now its only going to hash the letter a simply for testing purposes. The problem is that when it writes to the file I get:

One more thing: you probably need to add code.stdout.close() after you are done with the subprocess output. In this case, probably right after the for loop that writes out the lines. That file was opened for you in the .Popen() call and I don't think it gets closed automatically.

Your program will work with or without the .close() but it's good form to close files when you are done with them. Otherwise (for example) you may find your program runs for a while then mysteriously stops working. Not that I'm speaking from experience or anything ;)