473,614 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6940
¹é¿ø¼® 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
8251
by: John Bowling | last post by:
I have a java (2.0) program with the following lines: String cmdArray1 = {"lp", "-d", "hp4m", "MyFile"}; System.out.println(Runtime.getRuntime().exec(cmdArray1)); It compliles properly, but does not print the file to the printer. It displays the following as the return from Runtime...: java.lang.UNIXProcess@1034bb5
12
2117
by: km | last post by:
hi all, can any linux command be invoked/ executed without using shell (bash) ? what abt security concerns ? regards, KM
2
7478
by: bbxrider | last post by:
for win2k adv server/iis5.0 trying to run an external program from my asp routine that has multiple parameters, see following set shell = server.createobject("wscript.shell") shell.Run """f:\phsData\htmldoc\htmldoc.exe"" --webpage -f phsnew.pdf phsnew.htm" program either doesn't get invoked, or has an error, but since it has no error log i can't check that,
8
1333
by: Siemel Naran | last post by:
Hi. I'm writing a command shell that reads commands from standard input. At this point I have the command in a std::string. Now I want to execute this command in the shell. From the Borland newsgroups I learned that there is a function in stdlib.h called system. int system(const char *command); First question, is the system command ANSI compliant. Because I include <cstdlib> and write std::system(command.c_str()); it looks like an...
8
35035
by: zhiwei wang | last post by:
I remember that there is a function that could invoke shell command such as "rm" "cp", directly in .c file. But I could not recall its name, and I googled with nothing meaningful. I vaguely remember it is like: foo("cp file1 file2"); it is that simple, but cant remember. Could anyone here give me a clue?
1
3651
by: Fei Yuan | last post by:
Please forgive me re-posting this question since I wasn't clear in my original post. --------> Starting an external process needs to pass it a ProcessStartInfo() object. ProcessStartInfo has a property "UseShellExecute" that can open/print a file. For example, here's a piece of code that launches an external process to open a Microsoft Word Document: Process p = new Process();
1
8226
by: Rafael Fernandez | last post by:
Hi folks, I have the following sql/pl: CREATE PROCEDURE DBSTG.TEST (OUT PRESULT INTEGER ) SPECIFIC DBSTG.TEST DYNAMIC RESULT SETS 1 LANGUAGE SQL
25
62490
by: dennijr | last post by:
ok, shell always used to be easy for me, now its starting to get annoying cause i dont know wats wrong heres the simplist code possible: Private Sub IExplorer_Click() a = Shell("C:\Program Files\Internet Explorer\Iexplore.exe http://www.google.ca", vbMaximizedFocus) End Sub i have a program thats been on my desktop for about a month now that uses these 3 lines of code(supposed to be 3 lines but it doesnt quite fit) and its been...
7
6225
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke this shell script using the Subprocess module. Here is my code: def resultFromRunning_(command):
0
8198
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8142
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8642
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8591
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8294
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8444
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5549
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2575
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1438
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.