1

I want to run a shell script from a php-based website on my localhost (using MAMP on Mac) but it does not work, unfortunately.

Heres's the shell script:

#!/bin/bash
open /Users/my_username/Desktop/aiSee.app

If I run it from the terminal, it works fine and opens the app. Using this code in my website, it does not work:

<?php 
    echo exec('script.sh');
?> 

No errors or something are displayed, it just doesn't work. The script is located at the same source as the .php file for the website.

mishik
  • 9,973
  • 9
  • 45
  • 67
Oliver
  • 19
  • 5

2 Answers2

0

open in bash does not do what you think it does. You need cat instead:

#!/bin/bash
cat /Users/my_username/Desktop/aiSee.app
mishik
  • 9,973
  • 9
  • 45
  • 67
  • thanks a lot, i´ve tried it - but it dosn´t work either. I´m not a terminal pro, but isn´t cat for concatenating files somehow ? – Oliver Jul 01 '13 at 08:01
  • `cat` is for listing the file too. Does your shell file have '+x' permission? What will happen if you run `your_script.sh`? – mishik Jul 01 '13 at 08:15
  • It has +x permisson, done by: chmod +x sript.sh. If I try to execute it from the terminal ist says /Users/.../aiSee.app is a directory. With "open" instead of "cat" it did actually open the aiSee Application. Could it be possible, that there is a problem between localhost (MAMP) and the native shell, running in the OS ? – Oliver Jul 01 '13 at 11:02
  • "/Users/.../aiSee.app is a directory"? Ok what do you actually want to achieve in the first place? – mishik Jul 01 '13 at 11:10
  • I actually want to open aiSee. It´s an application that is able to draw graphs. The aim is to run it from a webapplication (localhost is ok for now) and i thought, the easiest way was to do it by a shellscript. In fact, if everything runs properly on a server, the script would be executed there. – Oliver Jul 01 '13 at 11:27
  • I don't think you can simply do that. I.e. if you have some application running on localhost - you can't just push into web by having php script execute it. – mishik Jul 01 '13 at 13:28
0

Has your issue been solved? If not, try echo exec('sh script.sh'); or echo exec('bash script.sh');. This question may solve your problem: how to run a .sh file from php?

Community
  • 1
  • 1
keshr3106
  • 413
  • 3
  • 10
  • 21