468,249 Members | 1,489 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,249 developers. It's quick & easy.

How can I run shell command without getting return?

Hello, everybody.

I want to call any shell command from php script using shell_exec(). The
problem is that the next line of the php script would not be run until a few
minutes after running the shell command.
I found the shell command couldn't be run at background mode. It seemed that
the shell_exec() function waits a return from the command. Because the
command doesn't return, the shell_exec() waits until timeout reached. Using
the '&' at the end of the command doesn't work expected.
So I want to know how can I run any non-background mode shell command from
php script without waiting return.
I'll look forward to any answer.
Thanks in advance.
Mar 9 '06 #1
2 6670
백원석 wrote:
Hello, everybody.

I want to call any shell command from php script using shell_exec(). The
problem is that the next line of the php script would not be run until a few
minutes after running the shell command.
I found the shell command couldn't be run at background mode. It seemed that
the shell_exec() function waits a return from the command. Because the
command doesn't return, the shell_exec() waits until timeout reached. Using
the '&' at the end of the command doesn't work expected.
So I want to know how can I run any non-background mode shell command from
php script without waiting return.
I'll look forward to any answer.
Thanks in advance.

If nothing else, you could probably do a shell wrapper to background it.
e.g.

#!/bin/bash
nohup foo &

-david-

Mar 9 '06 #2
Hello

The proc_open or popen functions may be used.

If you use one of these funtions then your script will not wait for the
shell command to exit and will immediately carry on running your
script.

Popen is easier to use but proc_open is more powerful,

http://www.php.net/manual/en/function.proc-open.php
http://www.php.net/manual/en/function.popen.php

Tim

Mar 9 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by John Bowling | last post: by
12 posts views Thread by km | last post: by
8 posts views Thread by Siemel Naran | last post: by
8 posts views Thread by zhiwei wang | last post: by
1 post views Thread by Rafael Fernandez | last post: by
reply views Thread by kermitthefrogpy | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.