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

  • SEARCH
  • Home
  • 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 6646761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:27:23+00:00 2026-05-26T00:27:23+00:00

I have a Python program that parses files, takes a path as and argument

  • 0

I have a Python program that parses files, takes a path as and argument and parses all files in the given path and all sub directories – using os.walk(path). I want to call this from my php Web App, so the user can specify a path, which is then passed as an argument to the parser. (Passing a path is ok because its all on an internal network).

I can call the parser fine and pass the arguments ok using popen(), but the path that the Python program receives is always invalid. I have had the php script output the command it is sending to the browser. If I copy and paste that command into a command window, the parser works fine.

I know the path the php script passes is invalid from the result of os.path.exists(path) in the Python script

This is the code to call the Python program:

$path = $_REQUEST['location'];
echo "Path given is: ".$path;
$command = 'python C:\Workspaces\parsers\src\main\main.py '. intval($mode).'  "'.$path.'"';
echo "<p>".$command."</p>";
$parser = popen($command, 'r');
if ($parser){
  echo "<p>Ran the program</p>";
  while (!feof($parser)){
    $read = fgets($parser);
    if (!$read)
      echo "<p>Reached end of file</p>";        
      else
        echo "<p>".$read."</p>";                 
    }
  }

The command echoed in the browser is like:

python C:\Workspaces\parsers\src\main\main.py 2 "I:\Dir1\Dir2\Dir3"

Where the 2 is just another argument to the script and $_REQUEST['location'] is defined from an input text box in a form on the calling page.

This is on a Windows system, so I am assuming this has something to do with the backslashes in the path.

Basically, I am unsure as to how all the backslashes are being handled. I would like to understand how strings containing backslashes are sent to the php page, and how they are sent again using popen(). I think the result being printed to the browser is not the raw command string, and I can’t be sure how many backslashes are really in the command being issued by popen().

If anyone has any ideas I’d really appreciate it.

Edit:

So in the Python program the path is used as follows:

 nfiles=0
 print 'Parsing all files in directory tree '+path+"<br />"
 start = time.time()
 if not os.path.exists(path):
   print "<p>Path is NOT REAL!!!</p>"
 else:
   print "<p>Path IS real!</p>"
 for root, dirs, files in os.walk(path):
   for f in files:
     file = os.path.join(root,f)
     print file
     nfiles+=1
     ...Code to run parser...
 print nfiles, "Files parsed<br />"

This is echoed back to the browser from the $read variable.

Output of that is:

Parsing all files in directory tree I:\Dir1\Dir2\Dir3
Path is NOT REAL!!!

0 Files parsed

This is identical to the output if the command is run from the command line (the command being copied from the browser and pasted into the cmd window). EXCEPT, when run that way the path IS real, and all the files are parsed. (and in the command window the html markup shows too)

The web server and parsers are hosted on my local machine.

  • 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-05-26T00:27:23+00:00Added an answer on May 26, 2026 at 12:27 am

    Check to see what user the PHP server is running as. If I:\ is a network drive, don’t expect those to be mapped under that user. Use a UNC path instead.

    Things to try:

    • a different path (we know C:\Workspaces\parsers\src\main\ works, why don’t you try that?)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a python program that reads floating point values using the following regular
I have a Python program that uses the threading module. Once every second, my
I have a python program that opens several urls in seperate tabs in a
I have a python program that is going to eat a lot of memory,
I have a simple python program that I'd like to daemonize. Since the point
I have a python program/file that I want to run repeatedly and calculate the
I have a Python program (with Django - does this matter?) that I want
I have an old C# program that is being ported to Python 3 for
I have a Python script that calls an executable program with various arguments (in
I have a Python script that needs to execute an external program, but for

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.