473,386 Members | 1,766 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,386 software developers and data experts.

using quotes in exec( ) or escapeshellcmd( )

LRW
I have a command I need to run in a shell:

/usr/bin/mogrify -size 180x180 -colors 256 -colorspace RGB +profile
"*" /usr/shipthumbs/*.tif

I've tried doing this:

$mog = "/usr/bin/mogrify -size 180x180 -colors 256 -colorspace RGB
+profile \"*\" /usr/shipthumbs/*.tif";
exec("$mog 2>&1", $output);

and

$mog = escapeshellcmd("/usr/bin/mogrify -size 180x180 -colors 256
-colorspace RGB +profile \"*\" /usr/shipthumbs/*.tif");
exec("$mog 2>&1", $output);

and

$mog = escapeshellcmd('/bin/bash -c "/usr/bin/mogrify -size 180x180
-colors 256 -colorspace RGB +profile "*" /usr/shipthumbs/*.tif'");
exec("$mog 2>&1", $output);

And no matter when I do, when that PHP script runs and I do a "ps aux"
I see the command line it's running always has the quotes that NEED to
be there ( "*" ) wrong.
either it's "\*" (yes I have the slash in the right place) or just *
without the quotes.

What's thr right way to formulate an exec() or an escapeshellcmd() so
that double quotes that HAVE to be sent to the shell get there?

Thanks!!
Liam
Jul 17 '05 #1
6 5268
*** LRW wrote/escribió (29 Jun 2004 13:21:57 -0700):
I have a command I need to run in a shell:

/usr/bin/mogrify -size 180x180 -colors 256 -colorspace RGB +profile
"*" /usr/shipthumbs/*.tif


Please note that * is a special char in most Unix shells. It's replaced by
all files in current directory. If you don't want it to be parsed you have
to enclose it between *single* quotes:

'*'
--
--
-- Álvaro G. Vicario - Burgos, Spain
--
Jul 17 '05 #2
LRW
Alvaro G Vicario <al******************@telecomputeronline.com> wrote in message news:<cm****************************@40tude.net>.. .
*** LRW wrote/escribió (29 Jun 2004 13:21:57 -0700):
I have a command I need to run in a shell:

/usr/bin/mogrify -size 180x180 -colors 256 -colorspace RGB +profile
"*" /usr/shipthumbs/*.tif


Please note that * is a special char in most Unix shells. It's replaced by
all files in current directory. If you don't want it to be parsed you have
to enclose it between *single* quotes:

'*'

I've confirmed that my whole problem with getting this Linux shell
command to run hinges on being able to send "*" to the command shell.
I don't quite understand what you suggested.

If I change the line:
exec("/usr/bin/mogrify -size 180x180 -resize 180x180 -quality 90
-colors 256 -colorspace RGB +profile "*" /usr/shipthumbs/*");
to
exec("/usr/bin/mogrify -size 180x180 -resize 180x180 -quality 90
-colors 256 -colorspace RGB +profile '*' /usr/shipthumbs/*");

then the command line will receive:
mogrify -size 180x180 -resize 180x180 -quality 90 -colors 256
-colorspace RGB +profile "*" /usr/shipthumbs/*
?
The mogrify command NEEDS to have: +profile "*" including the double
quotes and the asterik.

Thanks,
Liam
Jul 17 '05 #3
LRW
de**@celticbear.com (LRW) wrote in message news:<3a**************************@posting.google. com>...
I have a command I need to run in a shell: I've tried doing this:

$mog = escapeshellcmd("/usr/bin/mogrify -size 180x180 -colors 256
-colorspace RGB +profile \"*\" /usr/shipthumbs/*.tif");
exec("$mog 2>&1", $output);


And this is the "ps aux"

apache 8890 0.0 0.4 4956 1044 ? S 10:36 0:00 sh -c
/usr/bin/mogrify -size 180x180 -colors 256 -colorspace RGB +profile
"\*" /usr/shipthumbs/\*.tif 2>&1

apache 8891 0.0 5.0 21420 12864 ? R 10:36 0:32
/usr/bin/mogrify -size 180x180 -colors 256 -colorspace RGB +profile \*
/usr/shipthumbs/*.tif

I escape the dblquotes but they're not evidently being sent to the
command shell. And how do I prevent the backslash being sent in front
of the asterik? The asterik in the file path ends up without one but
the one that NEEDS to be surrounded by dblquotes still gets the
backslash on the command.

I've tried seemingly every combination of slashes and quotes on the
+profile "*" portion of the mogrify line, and nothing seems to send
exactly: +profile "*"
to the command shell.

Thanks for any help!
Liam
Jul 17 '05 #4
LRW wrote:
de**@celticbear.com (LRW) wrote in message news:<3a**************************@posting.google. com>...
I have a command I need to run in a shell:

I've tried doing this:

$mog = escapeshellcmd("/usr/bin/mogrify -size 180x180 -colors 256
-colorspace RGB +profile \"*\" /usr/shipthumbs/*.tif");
exec("$mog 2>&1", $output);

Try this (I don't like double quotes!):

$mog = '/usr/bin/mogrify -size 180x180 -colors 256 ';
$mog.= '-colorspace RGB +profile ';

$mog.= escapeshellarg('"*"') . ' ';

$mog.= '/usr/shipthumbs/*.tif';
exec($mog . ' 2>&1', $output);
--
USENET would be a better place if everybody read: | to email me: use |
http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
http://www.netmeister.org/news/learn2quote2.html | header, textonly |
http://www.expita.com/nomime.html | no attachments. |
Jul 17 '05 #5
*** LRW wrote/escribió (30 Jun 2004 08:26:31 -0700):
I've confirmed that my whole problem with getting this Linux shell
command to run hinges on being able to send "*" to the command shell.
I don't quite understand what you suggested.
Please accept my excuses. I was talking by heart and I was wrong. As soon
as you enclose * with quotes (no matter if single of double) the shell
doesn't expand it. I was mistaken with variables ("$FOO" is different from
'$FOO').

The mogrify command NEEDS to have: +profile "*" including the double
quotes and the asterik.


I've always generated thumbs with this command:

exec('convert -antialias -resize 80x80 -sharpen 1x50 +profile "*" ' .
escapeshellarg($source).' '.escapeshellarg($dest));

Since mogrify also belongs to ImageMagick it should be pretty similar.

--
--
-- Álvaro G. Vicario - Burgos, Spain
--
Jul 17 '05 #6
LRW
Pedro Graca <he****@hotpop.com> wrote in message news:<sl*******************@ID-203069.user.uni-berlin.de>...
LRW wrote:
de**@celticbear.com (LRW) wrote in message news:<3a**************************@posting.google. com>...
I have a command I need to run in a shell: I've tried doing this:

$mog = escapeshellcmd("/usr/bin/mogrify -size 180x180 -colors 256
-colorspace RGB +profile \"*\" /usr/shipthumbs/*.tif");
exec("$mog 2>&1", $output);

Try this (I don't like double quotes!):

$mog = '/usr/bin/mogrify -size 180x180 -colors 256 ';
$mog.= '-colorspace RGB +profile ';

$mog.= escapeshellarg('"*"') . ' ';

$mog.= '/usr/shipthumbs/*.tif';
exec($mog . ' 2>&1', $output);


At first I thought you mean you didn't like the double-quotes around
the asterik, and I was going to agree with you saying "yeah, they're a
pain, but necessary," then I realized you evidently don't like double
quotes at all!! =)

I hadn't thought of breaking it up like that (obviously,) and it looks
like it will work. I'll need to try it later, as at the moment I found
a workaround that's terribly inefficient but works: I put the mogrify
command in a bash script and am having the PHP call the script thus
avoiding PHP having to escape any characters. I'd rather have it all
in the same PHP script, though...so I'll give it a try.

Thanks!!
Liam
Jul 17 '05 #7

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

Similar topics

0
by: Avnish Midha | last post by:
Does the Runtime.exec() method support parameters from non-native locales i.e. does it really support the entire unicode range of characters in the parameters. I am trying ot invoke a C++...
2
by: asd987 | last post by:
Hi, I use document.write in a HTML-document to display same information. Now I have a problem displaying text that sometimes contains two kinds of quotes simultanelisly. I don't know on...
4
by: Ken Miller | last post by:
Hi all, I'm very new to vb.net, and was trying to write a wrapper for a command line utility, the problem being the parameter to be called to it is a path, and will generally have spaces in it....
21
by: comp.lang.tcl | last post by:
set php {<? print_r("Hello World"); ?>} puts $php; # PRINTS OUT <? print_r("Hello World"); ?> puts When I try this within TCL I get the following error:
5
by: chenthil | last post by:
In my Java program I need to call two DOS batch programs namely call.bat and start.bat. First I need to start the batch program call.bat and once that program is completed, I need to call the other...
2
by: if1467 | last post by:
I am trying to have the following formula entered into a cell, but the "No" in the If statement is causing VB problems. Any work arounds? TotTx = "=If(Netting = 'No',If(" & MyCells(rownum2, 11)...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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,...
0
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...

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.