我尝试用open命令执行命令
set command "C:\Program Files(x86)\gs\bin\gswin32c.exe -sDEVICE=pdfwrite -o $createpdfpath D:/test/1/ghostscript/gs9.19/lib/viewjpeg.ps -c \"($Modifiedjpgpath) <</PageSize 2 index viewJPEGgetsize 2 array astore >> setpagedevice viewJPEG\""
set f [open "$command" "r"]
执行后我收到以下错误:
couldn't open "C:\Program Files(x86)\gs\bin\gswin32c.exe -sDEVICE=pdfwrite -o C:/sample/Et/Alpha_10H00000001.0.00000102.00000001/23.pdf D:/test/1/ghostscript/gs9.19/lib/viewjpeg.ps -c "(\\\\Test-PC\\TRAIL-P\\Ds\\PS\\0\\17\\Color_00000001.jpg) > setpagedevice viewJPEG"": no such file or directory
但是,如果我通过命令提示符执行相同的命令,它将jpg转换为pdf文件,没有任何错误。
答案 0 :(得分:1)
除非您的Windows设置与工厂运行不同,否则“C:\Program Files(x86)
”不正确,应为“C:\Program Files (x86)
”,请注意定义中缺少的空格。
类似于:
set command "C:\Program Files (x86)\gs\bin\gswin32c.exe........"
FWIW Ghostscript通常也不会安装到该目录中,我希望该目录的格式为“c:\ Program Files(x86)\ gs \ gsX.YY \ bin \ gswin32c”,其中X.YY是Ghostscript版本号。
答案 1 :(得分:1)
您遇到的主要问题是您没有将该命令作为管道运行。
您需要更改:
set f [open "$command" "r"]
为:
set f [open |$command "r"]
您的管道描述符中也可能存在拼写错误,我建议您将其构建为列表,file nativename
也可能很重要,而不是ghostscript解释器本身的名称,而是任何提供给它的文件名:
# Easiest to use / instead of \ in filenames inside Tcl, really
set gs "C:/Program Files (x86)/gs/bin/gswin32c.exe"
set psscript "D:/test/1/ghostscript/gs9.19/lib/viewjpeg.ps"
# The next bit is building some postscript to run
set thejpgfile [file nativename $Modifiedjpgpath]
set pscmd "($thejpgfile) <</PageSize 2 index viewJPEGgetsize 2 array astore >> setpagedevice viewJPEG"
# Compose everything into a subprocess invokation
set command [list $gs -sDEVICE=pdfwrite -o $createpdfpath [file nativename $psscript] -c $pscmd]
# Actually run it
set f [open |$command "r"]
我发现通常更简单的方法是尝试保持代码行更短,并使用变量为单个位提供有用的名称。它也更容易调试;你可以打印出任何看起来太神秘的东西。