Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8621841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:54:31+00:00 2026-06-12T06:54:31+00:00

I have a problem running another file from php. I want my php params

  • 0

I have a problem running another file from php. I want my php params to be the output of running a python file that calls another file itself.

Here is my php file:

<?php
    if (isset($_POST['submit'])) {
    $params = solve();
}

function solve() {
  exec("python array.py", $output);
  return $output;
}
?>

If array.py is simply:

if __name__ == "__main__":
    print 1
    print 2
    print 3
    print 4

I will get 1,2,3,4 for my output, but I as soon as I change array.py to the following file that calls os.system, I don’t get anything. So the new array.py is:

import os

def main():
    os.system("python test.py") #test.py creates tmp.txt with 4 lines w/ values 1,2,3,4


def output():
    f = open("tmp.txt", "r")
    myReturn = []
    currentline = f.readline()

    while currentline:
          val = currentline[:-1]  #Getting rid of '\n'
          val = int(val)
          myReturn = myReturn + [val]
          currentline = f.readline()
    f.close()
    return myReturn


if __name__ == "__main__":
     main()
     o = output()
     print o[0]
     print o[1]
     print o[2]
     print o[3]

Also if I just run test.py, the output is the file tmp.txt:

 1
 2
 3
 4

So now, when I run my php file, the output tmp.txt is not even created in the directory and as a result I don’t get any output from my php either.
I am not sure why this is happening because when I just run array.py myself, I get the desired output, and the tmp file is created.

EDIT:
I forgot to include: import os above.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:54:32+00:00Added an answer on June 12, 2026 at 6:54 am

    Change exec to:

    exec("python array.py 2>&1", $output)
    

    Or check the web server or php error log. This will return the error output from the python script to your php script (not normally what you want in production).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the problem running executable .jar file. I've created a project which contains
I have a problem in running a new project which I downloaded from github.
I have website that use XMLHttpRequest (jQuery, actually). I also have another site running
I want to securely move a big file from one computer to another, where
Problem: find ids that are in one file but not in another. Each file
I have a 1.3GB text file that I need to extract some information from
I have a problem running my jsp pages. My jsp pages has reference to
I have a problem running an insert query via C# OleDbCommand to an Access
I'm a beginner with jdbc ... I have a problem running this code :
I have a problem with running jquery: <!DOCTYPE html> <html> <head> <meta http-equiv=Content-Type content=text/html;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.