Search code examples
pythongoogle-app-engineprocessstdinbulkloader

How do I automate Google App Engine upload_data with --passin and subprocess.Popen?


Here is what I have:

process = subprocess.Popen(["cmd.exe",
                            "/c"
                            "appcfg.py",
                            "upload_data",
                            "--config_file=..\\bulkloader.yaml",
                            "--filename=" + generateXmlFilename(kind),
                            "--kind=" + kind,
                            "--url=" + getTargetGaeUrl(),
                            "--application=" + getTargetGaeApplication(),
                            "[email protected]",
                            "../"])

This works as expected, however, when I introduce "--passin" I can't seem to get it into stdin correctly. I have tried the following:

file = open("upload.pass")
process = subprocess.Popen([..., "--passin"], stdin=file)

as well as

process.stdin.write("myPassword")

and I have even tried (in a shot in the dark)

process = subprocess.Popen([..., "--passin", "< upload.pass"])

You might have noticed I am trying to do this on a Windows 7 machine.

Is this possible?

Update:

After posting this and reading it in a different format, I realized that I wasn't waiting on the process.

The solution is:

file = open("upload.pass")
process = subprocess.Popen([..., "--passin"], stdin=file)
process.wait()

That works perfectly. I am assuming since I wasn't waiting python wasn't injecting anything into the subprocess because I had already exited.


Solution

  • After posting this and reading it in a different format, I realized that I wasn't waiting on the process.

    The solution is:

    file = open("upload.pass")
    process = subprocess.Popen([..., "--passin"], stdin=file)
    process.wait()
    

    That works perfectly. I am assuming since I wasn't waiting python wasn't injecting anything into the subprocess because I had already exited.