By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,350 Members | 1,309 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,350 IT Pros & Developers. It's quick & easy.

using quotes in exec( ) or escapeshellcmd( )

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
*** 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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
*** 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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.