我有一个Shell脚本,是在PHP脚本中创建的(已授予完全权限)。当我尝试从终端运行Shell脚本时,没有出现任何错误,但该脚本不会运行(其中的任何命令都不执行)。然而,一旦我将Shell脚本的内容复制并粘贴到XCode中的新文件中,并覆盖旧的Shell脚本,它就可以正常运行。
有什么建议吗?我已经尝试很长时间了,但没有进展。
我认为问题在于从PHP脚本编写Shell脚本,因为在XCode或文本编辑器中编写时可以正常工作。
以下是编写Shell脚本的PHP脚本:
有什么建议吗?我已经尝试很长时间了,但没有进展。
我认为问题在于从PHP脚本编写Shell脚本,因为在XCode或文本编辑器中编写时可以正常工作。
以下是编写Shell脚本的PHP脚本:
<code>
$filePath = "/Applications/MAMP/htdocs/php/Batch/modulator/Release23/Library/irShell.sh";
$script = fopen($filePath, 'w+');
chmod($filePath, 0777);
fwrite($script,"#!/bin/sh");
$irPath = "/Applications/MAMP/htdocs/php/Batch/modulator/Release23/Library"; //path to .ir files
$modPath = "/Applications/MAMP/htdocs/php/Batch/modulator";
if($dir = opendir($irPath)){
while(($file = readdir($dir)) !== false){
$posA = strpos($file, ".IR");
$posB = strpos($file, ".ir");
$posC = strpos($file, ".Ir");
if ($posA == true){
$fileName = trim($file, ".IR");
$noT = substr_replace($fileName, "", 0, 1);
echo "$noT\n";
fwrite($script, "\r" . $modPath . "/mod -o " . $irPath . "/codes/" . $noT . " " . $fileName . ".IR");
}
else if ($posB == true){
$fileName = trim($file, ".ir");
$noT = substr_replace($fileName, "", 0, 1);
echo "$noT\n";
fwrite($script, "\r" . $modPath . "/mod -o " . $irPath . "/codes/" . $noT . " " . $fileName . ".ir");
}
else if ($posC == true){
$fileName = trim($file, ".Ir");
$noT = substr_replace($fileName, "", 0, 1);
echo "$noT\n";
fwrite($script, "\r" . $modPath . "./mod -o " . $irPath . "/codes/" . $noT . " " . $fileName . ".Ir");
}
}
}
</code>
以下是由PHP生成的shell脚本示例:
#!/bin/sh
/Applications/MAMP/htdocs/php/Batch/modulator/mod -o /Applications/MAMP/htdocs/php/Batch/modulator/Release23/Library/codes/1294 T1294.ir
/Applications/MAMP/htdocs/php/Batch/modulator/mod -o /Applications/MAMP/htdocs/php/Batch/modulator/Release23/Library/codes/1295 T1295.ir
/Applications/MAMP/htdocs/php/Batch/modulator/mod -o /Applications/MAMP/htdocs/php/Batch/modulator/Release23/Library/codes/1296 T1296.ir
\r
有点怀疑。 - Dennis Williamson\n
。您能否编辑您的答案,展示一下生成脚本的示例?请使用@Dennis,以便用户可以自动收到回复通知。 - Dennis Williamson