473,660 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:\writablefol der\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 3080
Andrew Crowe wrote:
Calling exec('echo hello >C:\writablefol der\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:\writablefold er\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:\writablefol der\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:\writablefold er\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\system 32\cmd.exe

so,
'"%COMSPEC%" /c echo hello > "C:\writablefol der\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\ImageMagi ck-6.0.1-Q16\convert.exe " logo:
R:\Work\folder\ folder\writable folder\logo.jpg

copying that directly into the command line runs fine, as does just running
exec('cmd.exe /c "C:\Program Files\ImageMagi ck-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.btinter net.com...
Pedro Graca wrote...
> Andrew Crowe wrote:
>
>>Calling exec('echo hello >C:\writablefol der\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:\writablefold er\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\system 32\cmd.exe

so,
'"%COMSPEC%" /c echo hello > "C:\writablefol der\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\ImageMagi ck-6.0.1-Q16\convert.exe " logo:
R:\Work\folder\ folder\writable folder\logo.jpg

copying that directly into the command line runs fine, as does just running
exec('cmd.exe /c "C:\Program Files\ImageMagi ck-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 '\writablefolde r\', 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
5101
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 "nobody", my server's web user) I can get the htpasswd.exe to run without a problem, but when passed through my php exec() function the .htpasswd file does not change. I'm not getting any errors, but I'm not getting any action either.
1
3239
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 "Data" box and not the "Description" box - not very user friendly!! I have no trouble at all in writing to the Windows NT Application Log.
14
2316
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 going to use .Net......I highly recommend signing up for the free KBAlertz newsletter at http://www.kbalertz.com/default.aspx. Looking at all of the errors and quirks sometimes makes me wonder if this thing is really ready for prime time.
3
4588
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 : -804 SQL0804N The application program parameters for the current request are not valid. Reason code "107". If a
0
1837
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: C:\temp\postgresql-8.0.0beta1\src>nmake /f win32.mak Microsoft (R) Program Maintenance Utility Version 6.00.8168.0 Copyright (C) Microsoft Corp 1988-1998. All rights reserved. cd include if not exist pg_config.h copy pg_config.h.win32 pg_config.h
3
6238
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 "help", "copyright", "credits" or "license" for more information. >>> print u"ä" ä >>> exec 'print u"ä"' Traceback (most recent call last): File "<stdin>", line 1, in ?
1
2137
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 END DECLARE SECTION; ...
7
2201
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 = "mask.exe -e \"TestString\""; $Result = exec($MaskData, $Output, $ReturnValue); echo("Result: ".$Result);
1
1344
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 issue: Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) on win32 Type "help", "copyright", "credits" or "license" for more information. 0
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8542
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7362
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1984
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.