I'm having huge trouble with passing commands to CMD from Python.
First, I open a CMD process:
cmdprocess = subprocess.Popen("cmd",
stdin = subprocess.PIPE,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE)
Then, I do something, for example:
for i in range(500):
#time.sleep(1)
command = ("dir > " + os.path.join("C:\\", str(i)) + "\r\n").encode("utf-8")
print(command)
cmdprocess.stdin.write(command)
So this is supposed to create 500 small text files in a folder. I tested it in Python 3.2 x64 and 3.2 x86 and the result for both is: it counts up to about 250-350 in the Python shell, and then just stops. No error, nothing. There are then the files 1-80 in the specified folder.
Now, I thought that maybe Python is too fast and so had it sleep(1) for 1 second between the commands. Now, it counts up to about 200 before the first file appears in the folder! and then stops at about 270.
What happens here and how can I force CMD to execute a command immediately?
mklinkcommand to create symlinks to files. I just tried to reduce the problem to a smaller, more general command which is easier to write and doesn't need any prerequisites. The problem is identical in both commands.