Python 如何从windows命令提示符运行Openscad
我试图在Windows7中通过命令提示符运行OpenScad。然而,我无法让它工作。 我将以下目录添加到路径Python 如何从windows命令提示符运行Openscad,python,subprocess,call,command-prompt,openscad,Python,Subprocess,Call,Command Prompt,Openscad,我试图在Windows7中通过命令提示符运行OpenScad。然而,我无法让它工作。 我将以下目录添加到路径 "C:\Program Files\OpenSCAD\" 并尝试运行以下脚本: from os import listdir from subprocess import call files = listdir('.') for f in files: if f.find(".scad") >= 0: # get all .scad files
"C:\Program Files\OpenSCAD\"
并尝试运行以下脚本:
from os import listdir
from subprocess import call
files = listdir('.')
for f in files:
if f.find(".scad") >= 0: # get all .scad files in directory
of = f.replace('.scad', '.stl') # name of the outfile .stl
cmd = 'call (["openscad.com", "-o", "{}", "{}"])'.format(of, f) #create openscad command
exec(cmd)
我也用openscad、openscad.exe、openscad.com试过,到目前为止还没有成功。
我得到的错误是:
Traceback (most recent call last):
File "C:\Users\Desktop\scad2stl.py", line 9, in <module>
exec(cmd)
File "<string>", line 1, in <module>
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 247, in call
with Popen(*popenargs, **kwargs) as p:
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 676, in __init__
restore_signals, start_new_session)
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 955, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The specified file could not be found
回溯(最近一次呼叫最后一次):
文件“C:\Users\Desktop\scad2stl.py”,第9行,在
行政主任(cmd)
文件“”,第1行,在
文件“C:\Users\AppData\Local\Programs\Python\Python35\lib\subprocess.py”,第247行,在调用中
将Popen(*popenargs,**kwargs)作为p:
文件“C:\Users\AppData\Local\Programs\Python\Python35\lib\subprocess.py”,第676行,在\uuu init中__
恢复信号,启动新会话)
文件“C:\Users\AppData\Local\Programs\Python\Python35\lib\subprocess.py”,第955行,在执行子进程中
startupinfo)
FileNotFoundError:[WinError 2]找不到指定的文件
有什么建议吗?我刚刚看到这个线程,我已经使用windows power shell使它工作,由于cmd原因无法使它工作。例如,这在cmd> openscad-o render.png--imgsize=20482048 assembly.scad 但它在power shell上确实起作用(请注意bigining中的./): ./openscad-o render.png--imgsize=20482048 assembly.scad 希望能有帮助。
致以最诚挚的问候此错误意味着找不到openscad.exe的路径。请注意,如果openscad.exe的路径确实在路径中。如果路径设置正确,我可以在Windows7和10上运行代码。在Python3.5及更高版本上,可以用
subprocess.run()
替换subprocess.call()