简体   繁体   English

在Mac OS X上从bash脚本调用时,php脚本无法运行

[英]php script does not run when called from bash script on MAC OS X

Following is a bash script run.command that I am trying to use to call a PHP script 以下是我试图用来调用PHP脚本的bash脚本run.command

  #!/bin/bash
  #!/usr/bin/php
  # Main script 

php -f generateTest.php

Why does this not run when I "double click" the bash script ? 为什么当我“双击” bash脚本时此命令无法运行? It runs on calling from the terminal on OS X 它在OS X的terminal上调用时运行

I get the error message 我收到错误消息

asehgal-MacBook-Pro:~ asehgal$ /Users/asehgal/projects/configtest/run.command ; exit;
Could not open input file: generateTest.php
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

I have used chmod +x to make it executable. 我已经使用chmod +x使其可执行。

Use the absolute path to your generateTest.php file and it should work, it's not working now because it's trying to find generateTest.php in your current working directory (where you are running run.command from) 使用您的generateTest.php文件的绝对路径,它应该可以工作,现在不起作用,因为它试图在当前工作目录(运行run.command的位置)中查找generateTest.php。

Example: 例:

#!/bin/bash
#!/usr/bin/php
# Main script 

php -f /Users/asehgal/projects/configtest/generateTest.php
cd -- "$(dirname "$BASH_SOURCE")"

This needs to be there after the shebang line. 在shebang线之后必须在那儿。 Thats because when the terminal opens to run a bash script, it defaults to the current users home directory. 那是因为当终端打开以运行bash脚本时,它默认为当前用户的主目录。 Hence, we need to change the path to the folder out of which we expect to run out of. 因此,我们需要更改我们预期将用完的文件夹的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM