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;
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
add a comment |
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
can you show us exactly what is your PHP script and what you type in the command line?
– user1334621
Mar 21 at 23:54
istmp/file.txta 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
add a comment |
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
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
php bash
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
istmp/file.txta 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
add a comment |
can you show us exactly what is your PHP script and what you type in the command line?
– user1334621
Mar 21 at 23:54
istmp/file.txta 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
add a comment |
1 Answer
1
active
oldest
votes
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered Mar 22 at 0:09
Chris LindenChris Linden
164
164
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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.txta 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