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

Problems writing with exec() on Win32

Hi guys,

I'm having trouble executing commands using exec() or system() that need to
write files.

I've set the permissions on CMD.EXE but I can't use exec() to write any
files, even if the folder I'm writing to has write access to IUSER account
and PHP can write to the folder directly.

eg. Calling exec('echo hello >C:\writablefolder\text.txt') does nothing,
but if I type that same command into a shell prompt it works fine.

Also just calling exec('echo hello') returns "hello" so it's definatly
executing the command.
Does anyone know how I can fix this? What I'm trying to do is use
ImageMagick to do some image manipulation. Version of PHP I'm using is 5
rc2 on Win2k IIS using the isapi module.

Thanks

Andrew
Jul 17 '05 #1
4 3056
Andrew Crowe wrote:
Calling exec('echo hello >C:\writablefolder\text.txt') does nothing,
but if I type that same command into a shell prompt it works fine.

Also just calling exec('echo hello') returns "hello" so it's definatly
executing the command.
Does anyone know how I can fix this? What I'm trying to do is use
ImageMagick to do some image manipulation. Version of PHP I'm using is 5
rc2 on Win2k IIS using the isapi module.


I can't test this, but I think the redirection in DOS (and all versions
of Windows) is not a command-like thing, but rather an interpreted
thing (sorry ... can't explain any better)

I mean: only command.com (or cmd.exe or whatever) can redirect, and you
have to call it directly

exec('command /c echo hello > C:\writablefolder\text.txt');

I just put this /c here from memory. It is probably wrong :)
Check with "command /?" the options available to command.com

.... You may need extra quotes there too

HTH
--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #2
Pedro Graca wrote...
Andrew Crowe wrote:
Calling exec('echo hello >C:\writablefolder\text.txt') does nothing,
but if I type that same command into a shell prompt it works fine.

Also just calling exec('echo hello') returns "hello" so it's definatly
executing the command.
Does anyone know how I can fix this? What I'm trying to do is use
ImageMagick to do some image manipulation. Version of PHP I'm using is 5
rc2 on Win2k IIS using the isapi module.

I can't test this, but I think the redirection in DOS (and all versions
of Windows) is not a command-like thing, but rather an interpreted
thing (sorry ... can't explain any better)

I mean: only command.com (or cmd.exe or whatever) can redirect, and you
have to call it directly

exec('command /c echo hello > C:\writablefolder\text.txt');

I just put this /c here from memory. It is probably wrong :)
Check with "command /?" the options available to command.com

.... You may need extra quotes there too

I broadly agree with this. The correct call should be to %COMSPEC% which, in
Win2k, is usually c:\winnt\system32\cmd.exe

so,
'"%COMSPEC%" /c echo hello > "C:\writablefolder\text.txt"'
(quotes are only needed if there are spaces in the filename, but usually a good
idea anyway)
Note that command.com is totally different in WinNT/2k/XP - don't use it.
at the command prompt, type- echo %comspec% and %comspec% /?

%COMSPEC% should always be in the environment variables. I don't know, but maybe
the exec() command interprets it for you.

Jul 17 '05 #3
I've tried using cmd /c but it still won't write any files.
this is what I'm actually trying to execute:
cmd.exe /c "C:\Program Files\ImageMagick-6.0.1-Q16\convert.exe" logo:
R:\Work\folder\folder\writablefolder\logo.jpg

copying that directly into the command line runs fine, as does just running
exec('cmd.exe /c "C:\Program Files\ImageMagick-6.0.1-Q16\convert.exe"') (it
returns the help text for image magick), is there anything else I could try
to get this working?
Thanks,

Andrew

"anon" <me@privacy.net> wrote in message
news:c9*********@titan.btinternet.com...
Pedro Graca wrote...
> Andrew Crowe wrote:
>
>>Calling exec('echo hello >C:\writablefolder\text.txt') does nothing,
>>but if I type that same command into a shell prompt it works fine.
>>
>>Also just calling exec('echo hello') returns "hello" so it's definatly
>>executing the command.
>>
>>
>>Does anyone know how I can fix this? What I'm trying to do is use
>>ImageMagick to do some image manipulation. Version of PHP I'm using is 5 >>rc2 on Win2k IIS using the isapi module. >
>
> I can't test this, but I think the redirection in DOS (and all versions > of Windows) is not a command-like thing, but rather an interpreted
> thing (sorry ... can't explain any better)
>
> I mean: only command.com (or cmd.exe or whatever) can redirect, and you > have to call it directly
>
> exec('command /c echo hello > C:\writablefolder\text.txt');
>
> I just put this /c here from memory. It is probably wrong :)
> Check with "command /?" the options available to command.com
>
> .... You may need extra quotes there too
>

I broadly agree with this. The correct call should be to %COMSPEC% which,

in Win2k, is usually c:\winnt\system32\cmd.exe

so,
'"%COMSPEC%" /c echo hello > "C:\writablefolder\text.txt"'
(quotes are only needed if there are spaces in the filename, but usually a good idea anyway)
Note that command.com is totally different in WinNT/2k/XP - don't use it.
at the command prompt, type- echo %comspec% and %comspec% /?

%COMSPEC% should always be in the environment variables. I don't know, but maybe the exec() command interprets it for you.


Jul 17 '05 #4
Andrew Crowe wrote...
I've tried using cmd /c but it still won't write any files.
this is what I'm actually trying to execute:
cmd.exe /c "C:\Program Files\ImageMagick-6.0.1-Q16\convert.exe" logo:
R:\Work\folder\folder\writablefolder\logo.jpg

copying that directly into the command line runs fine, as does just running
exec('cmd.exe /c "C:\Program Files\ImageMagick-6.0.1-Q16\convert.exe"') (it
returns the help text for image magick), is there anything else I could try
to get this working?

Well, that's a whole different kettle of fish from an echo command.
First question - does the 'echo>file.txt' example work??
If not, then you need to look at permissions.

I would have thought that a command that isn't 'in the shell' (echo, dir, etc)
would not need the command interpreter cmd.exe

Other thoughts:

cmd.exe /c START c:/progra~1/imag
a) use START, and b) use short filenames (dir /x)

Check your IUSR_? and IWAM_? permissions on cmd.exe and ImageMagick and the
picture/folder. It sounds like the first two are OK (if you get help output).
When you say '\writablefolder\', writeable for whom?
Tried Google?

Jul 17 '05 #5

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

Similar topics

3
by: starlightjen | last post by:
Hello, I'm trying to use php to update my htpasswd file. I have my permissions on .htpasswd set to 777, so it should be wide open. From the command line (when logged into the server as...
1
by: Craig Hurcum | last post by:
Hi, I'm trying to log a formatted event to the Windows NT Security Event Log but I am having problems. I can get events into the log, but always unformatted with the data appearing in the...
14
by: Jim Hubbard | last post by:
Are you up to speed on the difficulties in using the 1.1 .Net framework? Not if you are unaware of the 1,596 issues listed at KBAlertz (http://www.kbalertz.com/technology_3.aspx). If you are...
3
by: Dmitry Bond | last post by:
Hi All. After moving to new version of DB2 we faced with strange problem - code that worked fine with DB2 v7.2.x on DB2 v 8.1 sometimes write error message like the: ===message=== SQLCODE :...
0
by: Vidyasagara Guntaka | last post by:
Hi, I recently downloaded source code for 8.0.0 beta1. When I tried building the libpq for windows, I got some compilation errors. Following the compilation output:...
3
by: Thomas Heller | last post by:
I'm using code.Interactive console but it doesn't work correctly with non-ascii characters. I think it boils down to this problem: Python 2.4.3 (#69, Mar 29 2006, 17:35:34) on win32 Type...
1
by: edwald | last post by:
I have very little experience with DB2, but am writing a simple C program, with embedded SQL, that has among other things EXEC SQL BEGIN DECLARE SECTION; double F; /*...*/ EXEC SQL...
7
by: JahMic | last post by:
I'm having a problem with exec on my hosting server. Unfortunately, the hosting support seems to be anything but helpful. The following works fine on my localhost: <?php $MaskData =...
1
by: Matimus | last post by:
I think I'm going to create a new issue in Pythons issue database, but I wanted to run it by the news group first. See if I can get any useful feed back. The following session demonstrates the...
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: 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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.