Calling Bash script from PHP not outputting correct valuesGet the source directory of a Bash script from within the script itselfHow to iterate over arguments in a Bash scriptPHP: Delete an element from an arrayHow to check if a program exists from a Bash script?Pipe to/from the clipboard in Bash scriptHow to get a password from a shell script without echoingHow to set a variable to the output of a command in Bash?Check existence of input argument in a Bash shell scriptSet environment variables from file of key/pair valuesSuppress warning messages using mysql from within Terminal, but password written in bash script

What are these boxed doors outside store fronts in New York?

Can I make popcorn with any corn?

Why do falling prices hurt debtors?

Watching something be written to a file live with tail

Replacing matching entries in one column of a file by another column from a different file

How did the USSR manage to innovate in an environment characterized by government censorship and high bureaucracy?

Mathematical cryptic clues

How can bays and straits be determined in a procedurally generated map?

Do I have a twin with permutated remainders?

Why do I get two different answers for this counting problem?

Email Account under attack (really) - anything I can do?

Why doesn't Newton's third law mean a person bounces back to where they started when they hit the ground?

What's the output of a record cartridge playing an out-of-speed record

How to add double frame in tcolorbox?

A newer friend of my brother's gave him a load of baseball cards that are supposedly extremely valuable. Is this a scam?

Why does Kotter return in Welcome Back Kotter?

How does one intimidate enemies without having the capacity for violence?

Have astronauts in space suits ever taken selfies? If so, how?

What do the dots in this tr command do: tr .............A-Z A-ZA-Z <<< "JVPQBOV" (with 13 dots)

Is a tag line useful on a cover?

Smoothness of finite-dimensional functional calculus

Is it important to consider tone, melody, and musical form while writing a song?

Is a conference paper whose proceedings will be published in IEEE Xplore counted as a publication?

Voyeurism but not really



Calling Bash script from PHP not outputting correct values


Get the source directory of a Bash script from within the script itselfHow to iterate over arguments in a Bash scriptPHP: Delete an element from an arrayHow to check if a program exists from a Bash script?Pipe to/from the clipboard in Bash scriptHow to get a password from a shell script without echoingHow to set a variable to the output of a command in Bash?Check existence of input argument in a Bash shell scriptSet environment variables from file of key/pair valuesSuppress warning messages using mysql from within Terminal, but password written in bash script






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am attempting to call a bash script from PHP. When I run this bash script on my text file from the command line, I get the desired output. However, through PHP, it simply outputs nothing.

The following is my PHP code.



$output = shell_exec("path/to/script.sh tmp/file.txt");
echo $output;


Where path/to/script is, as it sounds, the path to the bash script, and tmp/file.txt is the argument for the script. The output of this is blank, yet when I run the bash script with the same input in the command line, it executes properly. Why is this?










share|improve this question






















  • can you show us exactly what is your PHP script and what you type in the command line?

    – user1334621
    Mar 21 at 23:54











  • is tmp/file.txt a relative path, sometimes you can have issues with what the working directory is when calling scripts from other locations. I see this a lot more on windows. So it may be that it is failing silently too.

    – ArtisticPhoenix
    Mar 22 at 4:51


















0















I am attempting to call a bash script from PHP. When I run this bash script on my text file from the command line, I get the desired output. However, through PHP, it simply outputs nothing.

The following is my PHP code.



$output = shell_exec("path/to/script.sh tmp/file.txt");
echo $output;


Where path/to/script is, as it sounds, the path to the bash script, and tmp/file.txt is the argument for the script. The output of this is blank, yet when I run the bash script with the same input in the command line, it executes properly. Why is this?










share|improve this question






















  • can you show us exactly what is your PHP script and what you type in the command line?

    – user1334621
    Mar 21 at 23:54











  • is tmp/file.txt a relative path, sometimes you can have issues with what the working directory is when calling scripts from other locations. I see this a lot more on windows. So it may be that it is failing silently too.

    – ArtisticPhoenix
    Mar 22 at 4:51














0












0








0


1






I am attempting to call a bash script from PHP. When I run this bash script on my text file from the command line, I get the desired output. However, through PHP, it simply outputs nothing.

The following is my PHP code.



$output = shell_exec("path/to/script.sh tmp/file.txt");
echo $output;


Where path/to/script is, as it sounds, the path to the bash script, and tmp/file.txt is the argument for the script. The output of this is blank, yet when I run the bash script with the same input in the command line, it executes properly. Why is this?










share|improve this question














I am attempting to call a bash script from PHP. When I run this bash script on my text file from the command line, I get the desired output. However, through PHP, it simply outputs nothing.

The following is my PHP code.



$output = shell_exec("path/to/script.sh tmp/file.txt");
echo $output;


Where path/to/script is, as it sounds, the path to the bash script, and tmp/file.txt is the argument for the script. The output of this is blank, yet when I run the bash script with the same input in the command line, it executes properly. Why is this?







php bash






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 21 at 23:30









ToasterFrogsToasterFrogs

154




154












  • can you show us exactly what is your PHP script and what you type in the command line?

    – user1334621
    Mar 21 at 23:54











  • is tmp/file.txt a relative path, sometimes you can have issues with what the working directory is when calling scripts from other locations. I see this a lot more on windows. So it may be that it is failing silently too.

    – ArtisticPhoenix
    Mar 22 at 4:51


















  • can you show us exactly what is your PHP script and what you type in the command line?

    – user1334621
    Mar 21 at 23:54











  • is tmp/file.txt a relative path, sometimes you can have issues with what the working directory is when calling scripts from other locations. I see this a lot more on windows. So it may be that it is failing silently too.

    – ArtisticPhoenix
    Mar 22 at 4:51

















can you show us exactly what is your PHP script and what you type in the command line?

– user1334621
Mar 21 at 23:54





can you show us exactly what is your PHP script and what you type in the command line?

– user1334621
Mar 21 at 23:54













is tmp/file.txt a relative path, sometimes you can have issues with what the working directory is when calling scripts from other locations. I see this a lot more on windows. So it may be that it is failing silently too.

– ArtisticPhoenix
Mar 22 at 4:51






is tmp/file.txt a relative path, sometimes you can have issues with what the working directory is when calling scripts from other locations. I see this a lot more on windows. So it may be that it is failing silently too.

– ArtisticPhoenix
Mar 22 at 4:51













1 Answer
1






active

oldest

votes


















0














This is hard to answer without seeing script.sh however I can see that shell_exec outputs null when it fails.



You could try using the exec() function to review the exit code of the script.
php manual exec()



so the code would be:



exec("path/to/script.sh tmp/file.txt", $output);
echo $output;


You might find that it's a permission issue stopping the process from making changes to it.



try changing the file permissions with chmod 777 tmp/file.txt






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55290739%2fcalling-bash-script-from-php-not-outputting-correct-values%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    This is hard to answer without seeing script.sh however I can see that shell_exec outputs null when it fails.



    You could try using the exec() function to review the exit code of the script.
    php manual exec()



    so the code would be:



    exec("path/to/script.sh tmp/file.txt", $output);
    echo $output;


    You might find that it's a permission issue stopping the process from making changes to it.



    try changing the file permissions with chmod 777 tmp/file.txt






    share|improve this answer



























      0














      This is hard to answer without seeing script.sh however I can see that shell_exec outputs null when it fails.



      You could try using the exec() function to review the exit code of the script.
      php manual exec()



      so the code would be:



      exec("path/to/script.sh tmp/file.txt", $output);
      echo $output;


      You might find that it's a permission issue stopping the process from making changes to it.



      try changing the file permissions with chmod 777 tmp/file.txt






      share|improve this answer

























        0












        0








        0







        This is hard to answer without seeing script.sh however I can see that shell_exec outputs null when it fails.



        You could try using the exec() function to review the exit code of the script.
        php manual exec()



        so the code would be:



        exec("path/to/script.sh tmp/file.txt", $output);
        echo $output;


        You might find that it's a permission issue stopping the process from making changes to it.



        try changing the file permissions with chmod 777 tmp/file.txt






        share|improve this answer













        This is hard to answer without seeing script.sh however I can see that shell_exec outputs null when it fails.



        You could try using the exec() function to review the exit code of the script.
        php manual exec()



        so the code would be:



        exec("path/to/script.sh tmp/file.txt", $output);
        echo $output;


        You might find that it's a permission issue stopping the process from making changes to it.



        try changing the file permissions with chmod 777 tmp/file.txt







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 22 at 0:09









        Chris LindenChris Linden

        164




        164





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55290739%2fcalling-bash-script-from-php-not-outputting-correct-values%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해