473,322 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

executing multiple shell commands via one exec()-call

I wrote a PHP shell script under Linux which puts all existing
[E]PS-Files within a directory into a list and should then start a
single Ghostview window for each file. Sounds simple, but it's not:

The following code provides for about half of the functionality I
wanted:

==============code starts
$bla = array();
foreach ($filelist as $file)
{
$bla[] = fopen("./trash/".$file.".tmp", "w");
exec ("gv ".$file." &", $bla);
}
===============code ends

Here, all files are opened one after another. The next file opens only
after closing the current one. Actually I don't know whether the
redirection of the output towards .tmp-files complies with the
intended purpose of the redirection. The PHP manual states that when
starting programs in background, the output would have to be
redirected to a stream or file, otherwise PHP would continue to run
until the respective program is terminated (which I really wouldn't
care about at all, if it did so...).

Then I thought about writing the line I would type manually for
opening all ps-files ('gv bla1.ps & ; gv bla2.ps&; ...') into a string
and then executing that string:

===============code starts
$command="";
$bla = fopen("./trash/tmp", "w");
foreach ($filelist as $i => $file)
{
if ($i < count($filelist) - 1)
{
$command = $command."gv $file & ; ";
}
else
{
$command = $command."gv $file &";
}
}
exec ($command, $bla);
===============code ends

sadly I get an error message from the shell:
================ error message starts
sh: -c: line 1: syntax error near unexpected token `;'
sh: -c: line 1: `gv uges_Boden.ps & ; gv ux_Boden.ps & ; gv
uy_Boden.ps &'
================ error message ends

where *_Boden.ps are the files I wanted to open. Confusing me
perfectly, when I copied the command of the error message's second
line and pressed <return>, the thing I wanted to achieve happened: All
three files opened in their own Ghostview window.

Can anybody explain to me, what I got wrong here?

Thanks a lot!
Falk
Jul 16 '05 #1
1 10880
I found out by the help of a work mate, the solution is to redirect
the standard streams of the shell (in/out/error) to /dev/null within
the system call:

==============code starts
foreach ($filelist as $file)
{
$bla = "gv ".$file;
exec ($bla." >/dev/null 1>/dev/null 2>/dev/null &);
}
===============code ends
That's all it takes. Works perfectly.

Greetz
Falk
Jul 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: LRW | last post by:
I'm using a PHP script to run some command line...commands, and they seem to half work. Here's what I have: <?php $mog = escapeshellcmd("/usr/bin/mogrify -size 180x180 -colorspace RGB +profile...
7
by: Oliver Gräser | last post by:
Hej, I want to run batchfiles via the Shell, but accessible in the Browser via IIS. Actually, I'd like the server to start a command line ntbackup if a users selects to do so on an ASP in his...
3
by: Florian | last post by:
I need to set multiple values for some SQL statements, for example SET NUMERIC_ROUNDABORT OFF GO SET ANSI_PADDING,ANSI_WARNINGS,CONCAT_NULL_YIELDS_NULL,ARITHABORT,QUOTED_IDENTIF IER,ANSI_NULLS...
7
by: Glenn Davy | last post by:
Hidely hodley everyone I'd like to run a series of of sql ddl statements against an msde2000 server. Normally I just deploy cmd file that impliments as osql statement, but I'd like to store the...
0
by: Bruceneedshelp | last post by:
My application starts logging and executes shell commands on startup. The application runs fine, except when it executes at boot time. In other words when I make it a "startup" application on my...
2
by: Mark | last post by:
hi, i've written a c++ program that converts one file type to another via two arguments (the input and output filenames). i want to execute this on my server, using something like ...
0
by: blueblueblue | last post by:
Hi, I am trying to execute my dts package from sql using command shell as exec master..xp_cmdshell 'dtsrun /Sfiutopiadb /Usa /P /NBulktest' The package works perfectly in enterprise...
3
by: ZhukovL | last post by:
I'm having some trouble implementing the handling of multiple pipes in a shell I'm writing. I was hoping someone could point me in the right direction because I really cant see where I'm going...
2
by: gagandutta01 | last post by:
Hi, Can anyone tell me how to execute a function declared in Oracle Package from Unix shell script? I created a shell script and after connecting to oracle database i am using exec @...
5
by: inetquestion | last post by:
I am looking for a web interface for shell commands or shell scripts. Does anyone know of any exexisting php scripts which would solve this requirement? PHP form accepts input from a user, then...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.