python
  • python-2.7
  • 2017-02-13 30 views 0 likes 
    0

    sox.exe`我从Windows CMD运行此命令成功行:运行`在Python

    c:\cygwin\bin\sox.exe -r 16000 -c 1 c:/work/out/in_fixed.s32 c:/work/out/out_float.f32

    然而,我无法从Python的运行:

    import subprocess 
    
    if __name__ == "__main__": 
    
        sox = 'c:/cygwin/bin/sox.exe' 
        in_fixed = 'c:/work/out/in_fixed.s32' 
        out_float = 'c:/work/out/out_fixed.f32' 
    
        cmnd = '-r 16000 -c 1 ' + in_fixed + ' ' + out_float 
    
        subprocess.call([sox, cmnd]) 
    

    疗法误差:

    /usr/bin/sox FAIL sox: Rate value ` 16000 -c 1 c:/work/out/in_fixed.s32 c:/work/out/out_fixed.f32' is not a positive number. 
    

    如何从python正确启动此命令?

    回答

    1

    尝试分开你的论点

    subprocess.call([sox, '-r', str(16000), '-c', str(1), in_fixed, out_float]) 
    

    如果不工作,你可以强制使用CMD与shell=True

    +0

    谢谢。不工作。我需要将16000和1放在引号中,所以这是有效的:subprocess.call([sox,'-r','16000','-c','1',in_fixed,out_float])。请邹先生解决答案。不过,这个解决方案不是很方便;我仍然想在一个变量中传递我的参数。 – Danijel

    +1

    然后作为一个变量传递并调用'sox.split()'...显然,当你的命令中有空格时不起作用。 –

    相关问题