473,494 Members | 2,223 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using Python instead of DOS shell scripts

I have a project of converting numerous DOS cmd shell scripts to Python. Is there a tutorial to
getting started?

Thanks, Jeff
Jul 18 '05 #1
9 3641
On 2004-09-14, Jeff Wagner <JW*****@hotmail.com> wrote:
I have a project of converting numerous DOS cmd shell scripts
to Python. Is there a tutorial to getting started?


Yes.

Try looking at www.python.org.

Or maybe google for "python tutorial"?

--
Grant Edwards grante Yow! Is it FUN to be
at a MIDGET?
visi.com
Jul 18 '05 #2
Hello Jeff,
I have a project of converting numerous DOS cmd shell scripts to Python. Is there a tutorial to
getting started?

Just read the tutorial at http://docs.python.org/tut/tut.html

Shana Tova.
--
------------------------------------------------------------------------
Miki Tebeka <mi*********@zoran.com>
http://tebeka.spymac.net
The only difference between children and adults is the price of the toys







Jul 18 '05 #3
* Jeff Wagner (2004-09-14 06:56 +0200)
I have a project of converting numerous DOS cmd shell scripts to Python. Is there a tutorial to
getting started?


There are no tutorials for this special task. The appropriate
replacement for a batch script would be a shell script unless you want
/much/ more clearity and functionality.

[Tutorials]
* A Byte of Python
http://www.python.g2swaroop.net/byte/index.html
http://www.g2swaroop.net/files/byte/..._xhtml_115.zip
http://www.g2swaroop.net/files/byte/...single_115.zip

* Non-Programmers Tutorial For Python
http://www.honors.montana.edu/~jjc/easytut/easytut/
http://www.honors.montana.edu/~jjc/easytut/easytut.zip
http://www.honors.montana.edu/~jjc/easytut/easytut.pdf

* Learning to Program
http://www.freenetpages.co.uk/hp/alan.gauld/tutor2/
http://www.freenetpages.co.uk/hp/alan.gauld/tutor.tgz

* How to Think Like a Computer Scientist - Learning with Python
http://www.ibiblio.org/obp/thinkCSpy/
http://www.ibiblio.org/obp/thinkCSpy...py.html.tar.gz
http://www.ibiblio.org/obp/thinkCSpy/dist/thinkCSpy.pdf

* Python 101
http://www.devshed.com/c/a/Python/Py...-1-Snake-Eyes/

* Dive Into Python
http://www.diveintopython.org/toc.html
http://diveintopython.org/download/d...n-html-5.0.zip
http://diveintopython.org/download/d...l-flat-5.0.zip
http://diveintopython.org/download/d...on-pdf-5.0.zip

* Handbook of the Physics Computing Course (Python language)
http://www.chemistry.ucsc.edu/~wgsco...a/handbook.pdf
Jul 18 '05 #4
Jeff Wagner wrote:
I have a project of converting numerous DOS cmd shell scripts to Python. Is there a tutorial to
getting started?


Some of the more important modules for your task are probably
- os: http://www.python.org/doc/2.3.4/lib/module-os.html
- os.path: http://www.python.org/doc/2.3.4/lib/module-os.path.html
- win32 extensions: https://sourceforge.net/projects/pywin32/

You should visit the Python Cookbook
(http://aspn.activestate.com/ASPN/Python/Cookbook/), which is also
available in book form.

Daniel
Jul 18 '05 #5
>>>>> "Jeff" == Jeff Wagner <JW*****@hotmail.com> writes:

Jeff> I have a project of converting numerous DOS cmd shell
Jeff> scripts to Python. Is there a tutorial to getting started?

It might be a good idea to post one of the bat scripts you want to
convert. The resident gurus might show you a python equivalent, which
you could then study for inspiration.
Jul 18 '05 #6
I am just getting started myself and can really recommend "learning
python" by Lutz and Aescher (O'Reilly). This book really starts at the
beginning, covers several OS, and really explains well. I only knew
some Java before, and have never been great at command line things, so
this book really helped me a lot. If you are already a pro with
computers and other languages it might be too detailed.
Jul 18 '05 #7
Hi Jeff,

Welcome to Python programming!

If you want to learn Python quickly and easily, I would HIGHLY recommend
that you check out "How to think like a computer scientist: Learning
with Python." It is a free, downloadable book that teaches Python from
the ground up. It also contains many fun, step-by-step examples for the
beginner to try out -- along with an object-oriented approach later in
the book.

Check it out:

http://www.greenteapress.com/thinkpython/

Byron
---

Jeff Wagner wrote:
I have a project of converting numerous DOS cmd shell scripts to Python. Is there a tutorial to
getting started?

Thanks, Jeff

Jul 18 '05 #8
On Tue, 14 Sep 2004 06:00:56 -0500, John Hunter <jd******@ace.bsd.uchicago.edu> wrotf:
>> "Jeff" == Jeff Wagner <JW*****@hotmail.com> writes:


Jeff> I have a project of converting numerous DOS cmd shell
Jeff> scripts to Python. Is there a tutorial to getting started?

It might be a good idea to post one of the bat scripts you want to
convert. The resident gurus might show you a python equivalent, which
you could then study for inspiration.


Thanks for all the good info. I think the best place for me to start is to write a small program
which will launch the DOS cmd scripts which already exist. Is there a way to launch the file located
at this location?

e:\scripts\CleanLogFiles.cmd

Also, some of these scripts exist on a different server than the one I have Python running on. Is
there a way to log onto another server via an TCP/IP address and launch DOS cmd scripts there?

In other words e:\scripts\CleanLogFiles.cmd might be on server located at 10.75.211.15 and my
workstation is located on 155.156.25.6

I will next post an example of one of the scripts.

Jeff
Jul 18 '05 #9
On Tue, 14 Sep 2004 06:00:56 -0500, John Hunter <jd******@ace.bsd.uchicago.edu> wrotf:
>> "Jeff" == Jeff Wagner <JW*****@hotmail.com> writes:


Jeff> I have a project of converting numerous DOS cmd shell
Jeff> scripts to Python. Is there a tutorial to getting started?

It might be a good idea to post one of the bat scripts you want to
convert. The resident gurus might show you a python equivalent, which
you could then study for inspiration.

Here is one of the scripts:

SETLOCAL

REM Check that we have enough command line arguments
IF [%4]==[] (
echo.Expecting 4 command line arguments: {INPUT_PREFIX} {OUTPUT_PREFIX} {INPUT_PATH} {OUTPUT_PATH}
GOTO :EOF
)

REM Pick up the environment variables that define the current operational
REM environment.
REM
REM NOTE: This line assumes that your current working directory is the
REM scripts directory!!
call .\Environment.cmd

REM read the configuration parameters
REM
set INPUT_PREFIX=%1
shift
set OUTPUT_PREFIX=%1
shift
set INPUT_PATH=%1
shift
set OUTPUT_PATH=%1
shift

REM VAR_DESIGNATOR is the symbol that surrounds a variable to be substituted in
REM the configuration files.
set VAR_DESIGNATOR=#

REM This variable holds the names of the strings that will be replaced in the
REM files. Each name must also correspond to a variable set above.
set ENV_NAMES=NAME INSTALLDIR SESSION BGIF SPFTNAME

REM This is the list of files that need to have substitutions done
set FILES=dConfig.xml rConfig.xml pConfig.xml FMConfig_local.xml FMConfig_NA.xml

REM the directory where scripts live (namely, the replaceStringInFile.pl
REM script)
set SCRIPTS_DIR=.\

REM generaet a random number to help distinguish my temporary files from other
REM processes
set MYRAND=%RANDOM%

REM First substitute the computer names in all the files
FOR %%F IN (%FILES%) DO (
IF EXIST %INPUT_PATH%.\%INPUT_PREFIX%%%F. (
REM Make an initial copy of the file to start from, as-is
copy /Y %INPUT_PATH%.\%INPUT_PREFIX%%%F %OUTPUT_PATH%.\%OUTPUT_PREFIX%%%F > nul

call :RESET_COUNTER
FOR %%S in (%COMPUTER_NAMES%) DO (
REM figure out what computer we are substituting for

call :INC_COUNTER

call :REPLACE_CURRENT_COMPUTER %%S %%F

REM delete the existing destination file, if it exists
del /Q %OUTPUT_PATH%.\%OUTPUT_PREFIX%%%F

REM rename/move the temporary file
move /Y %TEMP%.\%OUTPUT_PREFIX%%%F%MYRAND% %OUTPUT_PATH%.\%OUTPUT_PREFIX%%%F
)
)
REM else file does not exist
)

REM Substitute the environment variables in ENV_NAMES.

FOR %%F IN (%FILES%) DO (

IF EXIST %OUTPUT_PATH%.\%OUTPUT_PREFIX%%%F. (
REM (This loop assumes that all the files in FILES already exist in the
REM OUTPUT_PATH, since the prior loop put them there.)

FOR %%E in (%ENV_NAMES%) DO (
CALL :SET_ENV_VALUE %%E

CALL :REPLACE_ENV_VALUE %%E %%F

REM delete the original file
del /Q %OUTPUT_PATH%.\%OUTPUT_PREFIX%%%F

REM rename the temporary file
move /Y %TEMP%.\%OUTPUT_PREFIX%%%F%MYRAND% %OUTPUT_PATH%.\%OUTPUT_PREFIX%%%F
)
)
REM else file does not exist-skip it
)

ENDLOCAL

GOTO :EOF

REM ************************************************** **************************
REM Because the command shell expands the for loops only once, anything that
REM varies from one loop execution to the next has to be contained in a
REM separate subroutine. The following subroutines are, therefore, called from
REM within the loops above.
REM ************************************************** **************************

:RESET_COUNTER
set COMPUTER_COUNTER=0
GOTO :EOF

:INC_COUNTER
set /A COMPUTER_COUNTER+=1
set COMPUTER_KEYWORD=COMPUTER%COMPUTER_COUNTER%
REM i.e., exit the subroutine
GOTO :EOF

:REPLACE_CURRENT_COMPUTER
%SCRIPTS_DIR%.\replaceStringInFile.pl %VAR_DESIGNATOR%%COMPUTER_KEYWORD%%VAR_DESIGNATOR% %1
%OUTPUT_PATH%.\%OUTPUT_PREFIX%%2 %TEMP%.\%OUTPUT_PREFIX%%2%MYRAND%
GOTO :EOF

:SET_ENV_VALUE
REM Get value of %%1
echo.set ENV_VALUE=%%%1%% >%TEMP%.\setENV_VALUE%MYRAND%.bat
call %TEMP%.\setENV_VALUE%MYRAND%.bat

REM Clean up after myself
del /Q %TEMP%.\setENV_VALUE%MYRAND%.bat
GOTO :EOF

:REPLACE_ENV_VALUE
REM do substitution, placing results in a temporary file
%SCRIPTS_DIR%.\replaceStringInFile.pl %VAR_DESIGNATOR%%1%VAR_DESIGNATOR% %ENV_VALUE%
%OUTPUT_PATH%.\%OUTPUT_PREFIX%%2 %TEMP%.\%OUTPUT_PREFIX%%2%MYRAND%
GOTO :EOF
Jul 18 '05 #10

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

Similar topics

7
2751
by: Robin Becker | last post by:
I wonder if this is the right way to write a medusa(asyncore) server with the win32all framework. Other example services seem to create an event to pass the stop signal from SvcStop into a separate...
2
14337
by: Jorgen Grahn | last post by:
I couldn't think of a good solution, and it's hard to Google for... I write python command-line programs under Win2k, and I use the bash shell from Cygwin. I cannot use Cygwin's python package...
20
5154
by: Matthew Thorley | last post by:
My friend sent me an email asking this: > I'm attemtping to decide which scripting language I should master and > was wondering if it's possible to do > these unixy awkish commands in python:...
3
2097
by: Sara Khalatbari | last post by:
There are a lot of commands that I need to use in my code & I don't know how to do it Is there a way to use shell commands in Python code? __________________________________ Do you...
16
3917
by: John Salerno | last post by:
Hi all. I just installed Ubuntu and I'm learning how to use the bash shell. Aside from the normal commands you can use, I was wondering if it's possible to use Python from the terminal instead of...
14
5487
by: mistral | last post by:
Need compile python code, source is in html and starts with parameters: #!/bin/sh - "exec" "python" "-O" "$0" "$@" I have installed ActivePython for windows.
34
3920
by: Ben Sizer | last post by:
I've installed several different versions of Python across several different versions of MS Windows, and not a single time was the Python directory or the Scripts subdirectory added to the PATH...
24
2812
by: Mark | last post by:
Hi, I'm new to python and looking for a better idiom to use for the manner I have been organising my python scripts. I've googled all over the place about this but found absolutely nothing. I'm...
7
6199
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke...
0
7157
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,...
1
6873
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
5453
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,...
1
4889
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...
0
3088
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...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1400
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
644
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
285
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.