Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a python script within a bash file with php

Tags:

python

bash

php

I am trying to run a simple python script (name.py):

#!/usr/bin/env python 
 name = raw_input('What is your name?\n')
 print 'Hi, %s.' % name

with the following bash script(Helloworld.sh):

 #!/bin/bash

python name.py

through the following php

<!DOCTYPE html>
<html>

<body>

<?php
if (isset($_POST['Submit1'])) {

 echo shell_exec('sh /home/administrator/Desktop/Helloworld.sh');
}

  ?>
<form action="myfilename.php" method="post">
<p><Input Type = "Submit" Name ="Submit1" Value = "Save Parameters">

</form>
</p> 

</body>
</html>

The error in the log is:

python: can't open file 'name.py': [Errno 2] No such file or directory

The bash file works fine from the terminal. What should I do?

like image 296
Jack Avatar asked Sep 05 '26 00:09

Jack


1 Answers

try adding the line before executing python script

cd "$(dirname "$0")"

in your bash file?

like image 142
Aboud Zakaria Avatar answered Sep 07 '26 13:09

Aboud Zakaria



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!