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

How to run a command prompt EXE?

34
Hi All,

How do you run an executable that normally has to be run from the Windows Command Prompt? The EXE of interest is normally done by typing mrsidsdw.exe <dir>/sidFile.sid, while in the specific directory of the EXE. I want to get this EXE to batch process (it normally runs one at a time). In the current case, I have the EXE and the files in the same directory.

I have tried a few things, including the below code -- no luck. It runs without errors, but the EXE isn't executed b/c a file should be created out of it, but none is.

Expand|Select|Wrap|Line Numbers
  1. # Set the workspace.
  2. gp.Workspace = r"C:\Documents and Settings\jenn5214\My Documents\Projects\Process SDW"
  3.  
  4. # List all the raster datasets
  5. sidList = gp.ListRasters("*", "SID")
  6.  
  7. # Grab the first raster dataset.
  8. sid = sidList.Next()
  9.  
  10. # Loop through each raster dataset
  11. while sid:
  12.     os.system("mrsidsdw.exe " + sid)
  13.     print sid
  14.     sid = sidList.Next()
  15.  
  16. print "done!"
  17.  
Any suggestions would be greatly appreciated!!!
Feb 13 '08 #1
8 3105
dshimer
136 Expert 100+
does the
Expand|Select|Wrap|Line Numbers
  1. print sid
line properly report s single string which corresponts to the file name you are expecting? Is mrsidsdw.exe in the path? When you say no errors, are you running the python program from the command line? And is it outputting anything at all?

I'm a little fuzzy on a couple things because I don't recognize the gp module, and the .Next() method. I would be more likely to just take a list and use a
Expand|Select|Wrap|Line Numbers
  1. for item in list:
method

Hi All,

How do you run an executable that normally has to be run from the Windows Command Prompt? The EXE of interest is normally done by typing mrsidsdw.exe <dir>/sidFile.sid, while in the specific directory of the EXE. I want to get this EXE to batch process (it normally runs one at a time). In the current case, I have the EXE and the files in the same directory.

I have tried a few things, including the below code -- no luck. It runs without errors, but the EXE isn't executed b/c a file should be created out of it, but none is.

Expand|Select|Wrap|Line Numbers
  1. # Set the workspace.
  2. gp.Workspace = r"C:\Documents and Settings\jenn5214\My Documents\Projects\Process SDW"
  3.  
  4. # List all the raster datasets
  5. sidList = gp.ListRasters("*", "SID")
  6.  
  7. # Grab the first raster dataset.
  8. sid = sidList.Next()
  9.  
  10. # Loop through each raster dataset
  11. while sid:
  12.     os.system("mrsidsdw.exe " + sid)
  13.     print sid
  14.     sid = sidList.Next()
  15.  
  16. print "done!"
  17.  
Any suggestions would be greatly appreciated!!!
Feb 13 '08 #2
jld730
34
does the
Expand|Select|Wrap|Line Numbers
  1. print sid
line properly report s single string which corresponts to the file name you are expecting? Is mrsidsdw.exe in the path? When you say no errors, are you running the python program from the command line? And is it outputting anything at all?

I'm a little fuzzy on a couple things because I don't recognize the gp module, and the .Next() method. I would be more likely to just take a list and use a
Expand|Select|Wrap|Line Numbers
  1. for item in list:
method

Oh, sorry... the gp module is specifc to my industry of GIS (gp = arcgisscripting.create() -- allows for geo-processing). The while loop is basically looping through all the images in a directory. The print statement simply prints out the current image file name, not important. No, mrsidsdw.exe is not in the print statement, if that is what you mean. No, I am running the python program from within Python. I was thinking that maybe i should be running the script from the command prompt and the script executes the EXE -- is that what I should be doing? ?? Sorry for my cluelessness -- I'm not a programmer by trade, obviously!

Pardon my cluelessness again, but wouldn't the while loop and for item is list do the same thing?

Thansk for your help!!!
Feb 13 '08 #3
dshimer
136 Expert 100+
Let me back up for a second, the question about the print statement didn't have anything to do with the mrsidsdw. Since it is there the print statement should output something each time through the loop, I was just trying to find out if the problem was that the file names weren't being passed properly to the command prompt. For example if they were, the filenames should be printed out one at a time to show the status of the processing. However if you are running the command from within a python editor like 'pythonwin' or something like that then the output of the command may not stay on the screen long enough for you to see.

I put a copy of mrsidsdw in a tmp directory. Then I went to a directory that contained a sid file, then I ran the following script called test.py by using the following command line (note that I have python fully installed and in my windows path).

python test.py

which contains
Expand|Select|Wrap|Line Numbers
  1. import os
  2. os.system(r'\tmp\mrsidsdw licking.sid')
mrsidsdw generates the following screen. So you can see that it should always output something, even if it was an error.

Z:\Laptop\PLSO_Technical\CherryValley>python tmp.py
mrsidsdw: (c) 2003 LizardTech, Inc. All rights reserved.

Image data:
width: 175000
height: 140000
has geo info: true
X UL: 1885000.500000
Y UL: 834999.500000
X res: 1.000000
Y res: -1.000000

World file licking.sdw created.

So you can see that the underlying premise is ok, there is just something in the application of it that would probably come out if you ran the python script from a command line and evaluated the output.
Feb 13 '08 #4
jld730
34
Let me back up for a second, the question about the print statement didn't have anything to do with the mrsidsdw. Since it is there the print statement should output something each time through the loop, I was just trying to find out if the problem was that the file names weren't being passed properly to the command prompt. For example if they were, the filenames should be printed out one at a time to show the status of the processing. However if you are running the command from within a python editor like 'pythonwin' or something like that then the output of the command may not stay on the screen long enough for you to see.

I put a copy of mrsidsdw in a tmp directory. Then I went to a directory that contained a sid file, then I ran the following script called test.py by using the following command line (note that I have python fully installed and in my windows path).

python test.py

which contains
Expand|Select|Wrap|Line Numbers
  1. import os
  2. os.system(r'\tmp\mrsidsdw licking.sid')
mrsidsdw generates the following screen. So you can see that it should always output something, even if it was an error.

Z:\Laptop\PLSO_Technical\CherryValley>python tmp.py
mrsidsdw: (c) 2003 LizardTech, Inc. All rights reserved.

Image data:
width: 175000
height: 140000
has geo info: true
X UL: 1885000.500000
Y UL: 834999.500000
X res: 1.000000
Y res: -1.000000

World file licking.sdw created.

So you can see that the underlying premise is ok, there is just something in the application of it that would probably come out if you ran the python script from a command line and evaluated the output.

I have seen that output when running the EXE from the command prompt. When I add Python to the mix, no luck. The looping works (it prints each raster), and I see the command prompt flash by briefly, but no .sdw file is created.

If I try running your [edited for me] script from the command prompt I get an error of "'python' is not recognized...'. That error along with your comment (note that I have python fully installed and in my windows path) above clued me in. Eventually I executed the command as C:\Python24\python process_sid.py, and that worked!!! .sdw files were created for all sids in the directory.

It occurs to me now that I don't even need the GP to get a list of rasters (GP can be a processing hog). How do you get a list of only .sid files in a particular directory -- I know that seems very elementary, I can do it with GP, but...
Feb 13 '08 #5
dshimer
136 Expert 100+
I only have a second and may contact you off list as one geomatic professional to another because I use python for tons of stuff. But quickly , check this out.
Expand|Select|Wrap|Line Numbers
  1. import glob
  2. filelist=glob.glob('*.tif')
  3. print filelist
  4. for filename in filelist:
  5.     print filename
  6.  
which returns

Z:\Laptop\PLSO_Technical\CherryValley>python test.py
['CherryValley.tif', 'CherryValleyDlg.tif', 'CherryValleyDoqq.tif', 'CherryValleyDrg.tif', 'OverlayOsip.tif', 'CherryValley1ft.tif']
CherryValley.tif
CherryValleyDlg.tif
CherryValleyDoqq.tif
CherryValleyDrg.tif
OverlayOsip.tif
CherryValley1ft.tif

Notice the list printed by
Expand|Select|Wrap|Line Numbers
  1.  print filelist
and the individual file names printed out (which could easily be processed in any way) within the for loop.
Feb 13 '08 #6
jld730
34
I only have a second and may contact you off list as one geomatic professional to another because I use python for tons of stuff. But quickly , check this out.
Expand|Select|Wrap|Line Numbers
  1. import glob
  2. filelist=glob.glob('*.tif')
  3. print filelist
  4. for filename in filelist:
  5.     print filename
  6.  
which returns

Z:\Laptop\PLSO_Technical\CherryValley>python test.py
['CherryValley.tif', 'CherryValleyDlg.tif', 'CherryValleyDoqq.tif', 'CherryValleyDrg.tif', 'OverlayOsip.tif', 'CherryValley1ft.tif']
CherryValley.tif
CherryValleyDlg.tif
CherryValleyDoqq.tif
CherryValleyDrg.tif
OverlayOsip.tif
CherryValley1ft.tif

Notice the list printed by
Expand|Select|Wrap|Line Numbers
  1.  print filelist
and the individual file names printed out (which could easily be processed in any way) within the for loop.

Awesome, that works great, faster then GP! Thanks for your help, and feel free to contact me off list. You'd be a great resource---maybe I can be of help to you, somehow ;-)

Final code, run from command prompt in directory where SIDs are located:
Expand|Select|Wrap|Line Numbers
  1. import glob, os
  2. filelist=glob.glob('*.sid')
  3. print filelist
  4. for filename in filelist:
  5.     print filename
  6.     os.system(r"C:\Temp\mrsidsdw.exe " + filename)
  7.  
  8.  
Feb 13 '08 #7
jld730
34
Awesome, that works great, faster then GP! Thanks for your help, and feel free to contact me off list. You'd be a great resource---maybe I can be of help to you, somehow ;-)

Final code, run from command prompt in directory where SIDs are located:
Expand|Select|Wrap|Line Numbers
  1. import glob, os
  2. filelist=glob.glob('*.sid')
  3. print filelist
  4. for filename in filelist:
  5.     print filename
  6.     os.system(r"C:\Temp\mrsidsdw.exe " + filename)
  7.  
  8.  

One last question... when I run the script in the command prompt, I have to type C:\Python24\python script.py, but you just had to type python script.py -- is there something that allows this????
Feb 14 '08 #8
dshimer
136 Expert 100+
One last question... when I run the script in the command prompt, I have to type C:\Python24\python script.py, but you just had to type python script.py -- is there something that allows this????
Let me answer at the introductory level since it will be here forever and you never know what level a reader may be at.
Assuming python is installed in c:\python24

  1. Right click "my computer"
  2. Select "Properties"
  3. Select "Advanced"
  4. Select "Environment Variables"
  5. Under "System Variables" select "Path"
  6. Select "Edit"
  7. In the "Variable Value" box, position the cursor all the way at the end and paste ;c:\python2
  8. Hit all the OK's necessary to get all the way out.
The string "c:\python24" adds that directory to the executable search path and the semi colon (;) is the separator between paths. This will also work with the path where your mrsidsdw.exe would be found. I have a utility directory that I keep for various command line programs that I rarely use and put that directory in the path. If I have a program that installs several command line programs in one place I can add that one using the same method. Then any time you start a command prompt window those directories will be searched for the name of an executable, or batch file matching the word you type eg: python.
Feb 14 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: msuk | last post by:
All, I am trying to use Regasm from the command prompt and have to keep putting the full file path of where my assembley is located. Does anyone know how to set it up so wherever I run the...
3
by: Rog | last post by:
Yes, I am guessing that typing cmd in the run windows will bring up the command prompt, but not the vs.net command prompt. Is there a switch(s) for accessing the vs.net command prompt? Or...
4
by: glenn | last post by:
I keep reading all sorts of books on VS that keep telling me to click on Tools/Visual Studio Command prompt to run this program or that program. However, I do not have such a menu choice. Where is...
4
by: Thomas Johnson | last post by:
I am trying to find out how to access the VS 2003 .Net command prompt. I am trying to execute the 'csc' command against a module but have no idea where to find the command prompt. Here's a stupid...
6
by: Jwolf | last post by:
I have .net 2002 edu version and when it installed there was a shortcut to the .net command prompt. My CLR disk is scratched so I can't reinstall and so I just downloaded express. I dont know...
6
by: Shooter4Life8 | last post by:
Hi, I am having trouble figureing out the best way to open a command prompt then write lines to it in VB.NET. Currently I have this code, but it execute's too fast I think because Dim psi As...
9
by: Endless Story | last post by:
My last version of Python was 2.4, running smoothly on XP with path c: \Python24 - no need even to include this path in PATH; everything worked as it's supposed to at the command line. Just...
4
by: Peter Nimmo | last post by:
Hi, I am writting a windows application that I want to be able to act as if it where a Console application in certain circumstances, such as error logging. Whilst I have nearly got it, it...
3
by: kimiraikkonen | last post by:
Hi experts, I just want to ask a simple procedure of my simple form. My form has a input textbox and a button. I want this if you can help me: Application user types a command prompt command...
7
by: Jwe | last post by:
Hi, I've written a program which has both a command line interface and Windows form interface, however it isn't quite working correctly. When run from command line with no arguments it should...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...

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.