作为Extendscript的输出之一,我希望创建一个shell脚本,然后用户可以执行该脚本。下面是一个非常基本的例子:
function createShellScript()
{
var contents = "#!/bin/bash\ndate";
var outputFolder = Folder.selectDialog ("Choose where to save:");
var shFile = new File(outputFolder.absoluteURI + "/shell.sh");
shFile.open("W");
shFile.write(contents);
shFile.close();
}
createShellScript ();如果我接受结果文件(shell.sh),在其上运行chmod +x以使其可执行,然后运行它,什么都不会发生。但是,如果我调整上面的脚本以创建相同的内容,但创建一个文本文件--因此它输出shell.txt,打开文件,将内容复制到代码编辑器中的空白文档中,然后保存为.sh文件,然后chmod并运行它,则可以正常工作。
为什么Extendscript在使用此方法时不生成正确的.sh文件?
谢谢你的帮助。
S
发布于 2014-10-09 14:15:52
您需要将行提要字符设置为unix样式。例如,shFile.lineFeed = "Unix";。
function createShellScript()
{
var contents = "#!/bin/bash\ndate";
var outputFolder = Folder.selectDialog ("Choose where to save:");
var shFile = new File(outputFolder.absoluteURI + "/shell.sh");
shFile.open("W");
shFile.lineFeed = "Unix";
shFile.write(contents);
shFile.close();
}
createShellScript ();https://stackoverflow.com/questions/26262723
复制相似问题