Hey all,

Trying to execute a command line from python. Here's some code:

class EncodeJob:
    def __init__(self,asset,recipe):
        self.asset = asset
        self.recipe = recipe
        self.original = self.asset.fullPath
        self.stdout = None
        self.stderr = None
        self.flv = os.path.normpath(self.recipe.configs['Flv Path'] + '/' + self.asset.filename.split('.')[0] + '.flv')
        self.thumb = os.path.normpath(self.recipe.configs['Thumb Path'] + '/' + self.asset.filename.split('.')[0] + '.jpg')
        ffmpeg_line = '"%s" -i "%s" %s "%s"' %(recipe.ffmpeg,self.original,asset.makeStr(self.recipe.configs),self.flv)
        [B]self.command = subprocess.Popen(ffmpeg_line, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)[/B]
    def encode(self):
        self.stdout,self.stderr = self.command.communicate()
        if os.path.exists(self.flv):
            return self.flv
        else:
            return "ERROR"
    def show_output(self):
        #if self.stdout and self.stderr:
        return """Standard Out:
%s
%s
Standard Error
%s""" %(self.stdout,Slumdog.bar(),self.stderr)
        #else:
            #return "Nothing to show"
    def cut_thumb(self):
        if os.path.exists(self.flv):
            cut_thumb(self.flv,self.thumb,self.recipe.configs,self.recipe.ffmpeg)
            if os.path.exists(self.thumb):
                return self.thumb
            else:
                return "ERROR"
        else:
            print "Flv does not exist, cannot cut thumb."
    def __str__(self):
        s = str(self.asset)
        return s

I put in bold the line that's throwing this error:

Traceback (most recent call last):
File "C:\Documents and Settings\zhobesh\Desktop\Thumb Cutter\cut_", line 12, in <module>
job = Casablanca.EncodeJob(asset,recipe)
File "\\carpenter\pylib\", line 40, in __init__
self.command = subprocess.Popen(ffmpeg_line, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
File "C:\Python26\lib\", line 595, in __init__
errread, errwrite)
File "C:\Python26\lib\", line 804, in _execute_child
startupinfo)
WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect

Here's my theory: I have my pylib set as a shared directory on shared computer, and that's screwing with the subprocess? I'm stumped.

Any and all theories/ideas/help is appreciated.

Thanks,

zac

Dani AI

Generated

Brief summary: that WindowsError 123 usually means the command you handed to CreateProcess was malformed (bad quoting, stray characters or an invalid/executable path). As suggested, inspect what you build; and as discovered, path/escaping mistakes are a common root cause. The safest pattern is to avoid composing one big quoted string and instead pass an argument sequence to subprocess so Python/Windows handle quoting for you.

Example (compatible with Python 2.6+ and 3.x):

# first element must be the executable path
args = [r"C:\Path\to\ffmpeg.exe",
        "-i", r"C:\path\input file.mov",
        "-y", r"C:\path\output file.flv"]

proc = subprocess.Popen(args,
                        stdout=subprocess.PIPE,
                        stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()

If you must produce a single command line on Windows (rarely needed), use subprocess.list2cmdline() to build a correctly quoted command string rather than hand-assembling quotes. Avoid shlex.split() on Windows (it follows POSIX rules). If you use shell=True you get different parsing and security tradeoffs — use it only when you need shell features.

Quick checklist for debugging:

  • Print repr(args) (or the string) before calling Popen.
  • Verify the first element (executable) exists and is executable.
  • Use absolute paths and os.path.abspath()/os.path.normpath() while building paths.
  • Test the same command copied into a cmd.exe prompt to see whether ffmpeg itself reports errors.
  • If the binary lives on a network share, try running it locally to rule out share/permission quirks.

Following the list-style call pattern eliminates most quoting/backslash headaches and makes failures easier to diagnose.

Recommended Answers

All 2 Replies

Maybe as a sanity check print out the contents of ffmpeg_line before calling the subprocess to make sure you've actually constructed the proper system call.

Also, the shared computer... is it a different platform? What is the purpose of that setup? I could imagine if you were running a script on a linux box with your version of PYthon that is installed on a Windows machine you'd run into many, many problems.

Turned out to be I was passing bad stuff in ffmpeg_line (backslashes and whatnot). Figured it out when it worked when I called it in a command prompt but not when I just ran the script itself.

Durrrr.

Thanks for the reply!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.