1

I need help in figuring out on how to generate an output file in python inside php script.

So here is the problem: I have a php script that lets user upload files. Those files are stored in the server. After that those files will be run on a python script, and will generate output files. After that the php script will get those output files, and send an email to the user. I want to make it automatically send to the user after they upload and click the submit button.

I have all those done, until trying to call a python script inside the php script The python script inside the php script does not execute the function where it generates the output files.

This is the function that I use for calling the bash script:

system('bash /data/home/rxs061/public_html/test.sh');

I also have used the function exec(); and shell_exec(); But does not work. The problem here, the function does not run on the command line, so the output file won't be generated.

This is inside the bash script (test.sh): python /home/rxs061/public_html/test.py outfile=$PWD/test.out echo "$PWD/"

The problem here it does not want to generate "test.out"

This is inside the the python script (test.py): import sys outfile = open('test.out', 'w') outfile.write('it worked\n') outfile.close()

This does not have to do with permissions. How do you put this all together in a single php script? Or are there any other solutions? Or how to make it output files???

5
  • test.sh is not a Python script, it's a bash script (which itself runs a Python script). Commented Oct 3, 2013 at 19:36
  • why dont u send the email in python? make everything async Commented Oct 3, 2013 at 19:37
  • More importantly: what is $PWD when you run test.sh? What were you hoping for it to be? Commented Oct 3, 2013 at 19:37
  • Finally, what do you mean by "does not work"? What does "does not run on the server/unix shell" mean? What actually happens? Commented Oct 3, 2013 at 19:38
  • @abarnert $PWD is the path. So If I run the exec('bash /data/home/rxs061/public_html/test.sh') or shell_exec("bash /data/home/rxs061/public_html/test.sh") or system("bash /data/home/rxs061/public_html/test.sh"), the intended output file that is inside the test.sh, that is test.out won't be generated. Because it only can be generated when I ran "bash /data/home/rxs061/public_html/test.sh" in the command line. Commented Oct 15, 2013 at 14:05

1 Answer 1

1

Oh I get all fix, it something to do with the permission. After I do chmod 777, it is all fixed

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.