using quotes in exec( ) or escapeshellcmd( )

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • LRW

    using quotes in exec( ) or escapeshellcmd( )

    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
  • Alvaro G Vicario

    #2
    Re: using quotes in exec( ) or escapeshellcmd( )

    *** LRW wrote/escribió (29 Jun 2004 13:21:57 -0700):[color=blue]
    > I have a command I need to run in a shell:
    >
    > /usr/bin/mogrify -size 180x180 -colors 256 -colorspace RGB +profile
    > "*" /usr/shipthumbs/*.tif[/color]

    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
    --

    Comment

    • LRW

      #3
      Re: using quotes in exec( ) or escapeshellcmd( )

      Alvaro G Vicario <alvaro_QUITAR_ REMOVE@telecomp uteronline.com> wrote in message news:<cmnhf9rac h6$.1x6zr852kk4 5r.dlg@40tude.n et>...[color=blue]
      > *** LRW wrote/escribió (29 Jun 2004 13:21:57 -0700):[color=green]
      > > I have a command I need to run in a shell:
      > >
      > > /usr/bin/mogrify -size 180x180 -colors 256 -colorspace RGB +profile
      > > "*" /usr/shipthumbs/*.tif[/color]
      >
      > 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:
      >
      > '*'
      >[/color]
      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

      Comment

      • LRW

        #4
        Re: using quotes in exec( ) or escapeshellcmd( )

        deja@celticbear .com (LRW) wrote in message news:<3a1d1813. 0406291221.19e7 5423@posting.go ogle.com>...[color=blue]
        > I have a command I need to run in a shell:[/color]
        [color=blue]
        > 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);
        >
        >[/color]

        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

        Comment

        • Pedro Graca

          #5
          Re: using quotes in exec( ) or escapeshellcmd( )

          LRW wrote:[color=blue]
          > deja@celticbear .com (LRW) wrote in message news:<3a1d1813. 0406291221.19e7 5423@posting.go ogle.com>...[color=green]
          >> I have a command I need to run in a shell:[/color]
          >[color=green]
          >> 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);[/color][/color]


          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. |

          Comment

          • Alvaro G Vicario

            #6
            Re: using quotes in exec( ) or escapeshellcmd( )

            *** LRW wrote/escribió (30 Jun 2004 08:26:31 -0700):[color=blue]
            > 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.[/color]

            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').

            [color=blue]
            > The mogrify command NEEDS to have: +profile "*" including the double
            > quotes and the asterik.[/color]

            I've always generated thumbs with this command:

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

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

            --
            --
            -- Álvaro G. Vicario - Burgos, Spain
            --

            Comment

            • LRW

              #7
              Re: using quotes in exec( ) or escapeshellcmd( )

              Pedro Graca <hexkid@hotpop. com> wrote in message news:<slrnce5os n.ih8.hexkid@ID-203069.user.uni-berlin.de>...[color=blue]
              > LRW wrote:[color=green]
              > > deja@celticbear .com (LRW) wrote in message news:<3a1d1813. 0406291221.19e7 5423@posting.go ogle.com>...[color=darkred]
              > >> I have a command I need to run in a shell:[/color][/color]
              >[color=green][color=darkred]
              > >> 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);[/color][/color]
              >
              >
              > 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);[/color]

              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

              Comment

              Working...