Re: Problems with exec() on windows

From: Date: Thu, 19 Mar 2009 14:28:39 +0000
Subject: Re: Problems with exec() on windows
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-290275@lists.php.net to get a copy of this message
On Thu, Mar 19, 2009 at 9:25 AM, haliphax <haliphax@gmail.com> wrote: > On Thu, Mar 19, 2009 at 9:19 AM, Kyohere Luke <pr0f3t@gmail.com> wrote: >> Hi, >> I'm trying to use exec to call gammu.exe and send sms on windows XP. >> >> This works from commandline: >> >> C:\path\to\gammu.exe 1 --sendsms EMS 200 -text "test1 test2" >> >> But if I run it through php like this: >> >> $command = "\"C:\path\to\gammu.exe\" --sendsms EMS 200 -text \"test1 >> test2\"".; >> @exec($command, $response, $retval); >> >> This always fails, returns 1 and the response is empty. >> >> If the last argument is a string with no spaces, and the double quotes were >> omitted, it works perfectly. >> >> If the double quotes are added around the string with no spaces, it fails >> again, which makes me believe that the problem is with the double quotes. >> >> I've used procmon and it shows that when the double quotes are added around >> the last argument, gammu.exe is not even called at all. >> >> Problem is that the double quotes are required by gammu to send an sms with >> spaces in it. > > I'm not sure if it will help, but the escapeshellarg() function looks > like it might handle all that tricky slash-and-quote-adding for you: > > http://php.net/escapeshellarg > > Other than that, perhaps proc_open() would do what you need it to by > completely separating the command's arguments from itself. > > http://php.net/proc_open Also--if you're only concerned with a one-way process tunnel (read or write, but not both) then maybe popen() instead of proc_open() would be preferable for overhead/speed. Of course, that's if either of them do what you're looking for. -- // Todd

« previous php.general (#290275) next »