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

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 3633
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
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
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
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
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
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
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
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
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
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
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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,...
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...

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.