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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:33:20+00:00 2026-05-23T19:33:20+00:00

Hii i have this code : $handle = popen(php -q nah.php -p=. ‘$part’ .

  • 0

Hii i have this code :

            $handle = popen("php -q nah.php -p=". '$part' . " 2>&1", "r");
            while (!feof($handle))
            {
                 $read = fread($handle, 2096);
                    echo $read;
            }
            pclose($handle);

And the the nah.php looks like this:

echo "yaya1\n";
$options = getopt("p:");
$part = $options["p"];
echo $part;
print_r($options);

The output of this comes out to be:

yaya1 Array (
[p] => )

While the $part in the main file has content.
What can be the error in it ?
How can i fix the error ?
Thanks
And all this is done in php-cli

  • 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-23T19:33:22+00:00Added an answer on May 23, 2026 at 7:33 pm

    You’ll want to replace the line that runs popen with this:

    $handle = popen("php -q nah.php -p=". escapeshellarg($part) . " 2>&1", "r");
    

    This uses the escapeshellarg() [docs] function in order to wrap the $part variable in quotes (and escape any quotes inside it), so that it can be used as a shell argument safely.

    The error was that you had $part within single quotes, so it was being sent to the shell directly as $part instead of the value being replaced by PHP. The shell then tried to look for a shell variable called $part to replace it with, but since there was none, it simply replaced it with a blank.

    This code would also have worked:

    $handle = popen("php -q nah.php -p=". $part . " 2>&1", "r");
    

    However, that would not have wrapped the variable in single quotes, so if there were any spaces in it, only the first word would have been considered the value of argument p, all the other ones would have been considered different arguments.

    It’s generally good practice to use escapeshellarg() when sending arguments to a shell command since it takes care of quoting the argument for you.

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

Sidebar

Related Questions

Hi i have problem in this code it says Object reference not set to
Hi I have this code using generic and nullable: // The first one is
Hi I have this ical (1.0 beta) I have this code IICalendarCollection iCal =
hi i have this html code : <div id=#div><a href=>Test</a></div> i want attach click
Hi I have a problem with a modem and win32 api. When I open
hii guys, i am working on a crossword application.I took UITextField to the respective
Hi i have some text which is meant to be displayed within a label.
Hi I wonder how to work around the problem I have with the pagination
hi i'm watching a c++ tutorial and instructor includes the libraries like this #
Hi i am going to store data into a local .db in my android

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.