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 8997835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:56:33+00:00 2026-06-15T23:56:33+00:00

I’m using the system() function in PHP to call a CLI program that I

  • 0

I’m using the system() function in PHP to call a CLI program that I need to use that is not currently available from within PHP (code below). I’m using xml2brl (liblouisxml) CLI to generate an output file that contains braille ASCII text. Using the code below, the two files are successfully created, and the first file has the input text successfully written to it; however, the output file (the second file) never gets the translated text written to it.

Here’s the strange part, though. Using the same command that is passed to system() and the same temp files that I create in PHP, I can successfully run the command as my user in Terminal. What could this issue be caused by? When I run whoami command through system(), I get my user, and no special permissions are required for either the temp files or the CLI command xml2brl.

Currently, I’m creating two temp files in PHP:

//Create the temporary files that will be passed to xml2brl
$_standardText = tempnam("~/tmp", "pll_");
$_translatedText = tempnam("~/tmp", "pll_");

The temp files are stored in /private/tmp, and have the pll_ prefix to them, to identify the files that the PHP script is creating.

Then, I’m writing the contents of the passed text to the temp file like this:

//Write the contents of the passed text to the temp file
$handle = fopen($_standardText, "w");
fwrite($handle, $text);
fclose($handle);

Now, the temp file located in /private/tmp/xxxx has the text written in it (verified this), and then I go ahead and format the command:

$command = escapeshellcmd("xml2brl -p" . " " . $_standardText . " " .  $_translatedText);

This has the format like this when echoing the $command variable:

xml2brl -p /private/tmp/pll_MYRy9m /private/tmp/pll_DmiK7E

And go ahead and run the exec command, which should process the input file and write the translated text to the output file, but it doesn’t:

exec($command);

Now, here’s the strange part… when I try to do just an ls, I can get the directory listing from my home directory and echo that out through the PHP script — signifying that I should have access to run the system and exec commands with Apache, but whenever this command runs, it doesn’t work. However, when I don’t delete the temp files, and use the same PHP-created command (xml2brl -p /private/tmp/pll_MYRy9m /private/tmp/pll_DmiK7E)and temp files in the CLI, I can run them under my user.

  • 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-15T23:56:34+00:00Added an answer on June 15, 2026 at 11:56 pm

    The first thing you should do (after making sure your script can run simple commands such as /bin/ls) is make full use of exec()‘s arguments:

    exec($command, $out, $code);
    if ($code) {
        // an error occurred while running the command
    }
    

    Second, make sure the paths are correct. xml2brl may be in your path, but perhaps not in the path of your script:

    $command = '/usr/bin/xml2brl -p ' . escapeshellarg($_standardText);
    
    exec($command, $out, $code);
    if ($code) {
        die("An error occurred while attempting torun xml2brl");
    } else {
        echo "Output was: ", join("\n", $out);
    }
    

    If that still doesn’t work, you can redirect stderr:

    exec("$command 2>&1", $out, $code);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a function that will clean a strings' special characters. I do NOT
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am using jsonparser to parse data and images obtained from json response. When

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.