[osgeo4w-dev] How to log Osgeo4W shell stdout into a txt file?
Matt Wilkie
matt.wilkie at gov.yk.ca
Mon Oct 22 14:51:45 PDT 2012
execfile can't take arguments, you need to use /subprocess.call/ instead:
import subprocess, sys
subprocess.call([sys.executable, 'apt.py', '2>mylogfile.txt'],
shell=True)
Be careful though, `shell=True` means you can easily bork your system if
your command is misconstructed, e.g. `rmdir /s/q C:\Windows` instead of
`rmdir /s/q C:\temp\Windows` would be disasterous.
http://stackoverflow.com/questions/5788891/execfile-with-argument-in-python-shell
http://stackoverflow.com/questions/912830/using-subprocess-to-run-python-script-on-windows
http://docs.python.org/library/subprocess.html
cheers,
matt wilkie
--------------------------------------------
Geomatics Analyst
Information Management and Technology
Yukon Department of Environment
10 Burns Road * Whitehorse, Yukon * Y1A 4Y9
867-667-8133 Tel * 867-393-7003 Fax
http://environmentyukon.gov.yk.ca/geomatics/
--------------------------------------------
On 22-Oct-2012 5:05 AM, Pietro Rossin wrote:
> Hi again
> I'm in osgeo4w shell in a python session.
> I'm executing a python script with the command
>
> execfile('myscript.py').
>
> Is there some way to log all possible errors given by this command?
>
> The script batch import dxf data to a postgis enabled database.
> May be sometimes some file is not well recognized and many messages are
> reported to the osgeo command window.
>
> If I write
> execfile('myscript.py') 2>c:\mylogfile.txt python gives me an error because
> it doesn't recognize the command..
>
>
> Thankyou again
> Pietro
>
>
>
> --
> View this message in context: http://osgeo-org.1560.n6.nabble.com/How-to-log-Osgeo4W-shell-stdout-into-a-txt-file-tp5009568p5010237.html
> Sent from the osgeo4w-dev -- OSGeo Win32 Installer List mailing list archive at Nabble.com.
> _______________________________________________
> osgeo4w-dev mailing list
> osgeo4w-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/osgeo4w-dev
> .
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/osgeo4w-dev/attachments/20121022/f2f17f13/attachment.html>
More information about the osgeo4w-dev
mailing list