473,729 Members | 2,409 Online
Bytes | Software Development & Data Engineering Community
+ 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 3655
On 2004-09-14, Jeff Wagner <JW*****@hotmai l.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*********@zo ran.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*****@hotmai l.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.b sd.uchicago.edu > wrotf:
>> "Jeff" == Jeff Wagner <JW*****@hotmai l.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\Clea nLogFiles.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\Clea nLogFiles.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.b sd.uchicago.edu > wrotf:
>> "Jeff" == Jeff Wagner <JW*****@hotmai l.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.c md

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.x ml rConfig.xml pConfig.xml FMConfig_local. xml FMConfig_NA.xml

REM the directory where scripts live (namely, the replaceStringIn File.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_NAME S%) DO (
REM figure out what computer we are substituting for

call :INC_COUNTER

call :REPLACE_CURREN T_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%MYR AND% %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_VA LUE %%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%MYR AND% %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_COUNTE R=0
GOTO :EOF

:INC_COUNTER
set /A COMPUTER_COUNTE R+=1
set COMPUTER_KEYWOR D=COMPUTER%COMP UTER_COUNTER%
REM i.e., exit the subroutine
GOTO :EOF

:REPLACE_CURREN T_COMPUTER
%SCRIPTS_DIR%.\ replaceStringIn File.pl %VAR_DESIGNATOR %%COMPUTER_KEYW ORD%%VAR_DESIGN ATOR% %1
%OUTPUT_PATH%.\ %OUTPUT_PREFIX% %2 %TEMP%.\%OUTPUT _PREFIX%%2%MYRA ND%
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%.b at

REM Clean up after myself
del /Q %TEMP%.\setENV_ VALUE%MYRAND%.b at
GOTO :EOF

:REPLACE_ENV_VA LUE
REM do substitution, placing results in a temporary file
%SCRIPTS_DIR%.\ replaceStringIn File.pl %VAR_DESIGNATOR %%1%VAR_DESIGNA TOR% %ENV_VALUE%
%OUTPUT_PATH%.\ %OUTPUT_PREFIX% %2 %TEMP%.\%OUTPUT _PREFIX%%2%MYRA ND%
GOTO :EOF
Jul 18 '05 #10

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

Similar topics

7
2765
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 termination method, but I'm unsure how that would mix with the polling loop. This simple framework seems to start and stop OK, but I wonder if I'm missing some obvious race or something.
2
14359
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 because of a binary module which has to be compiled with Visual C 6. My scripts start with a '#!/usr/bin/env python' shebang, as God intended. Now, I assume I can make cmd.exe run foo.py by asociating *.py with the python interpreter.
20
5191
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: > > How to find the amount of disk space a user is taking up: > > find / -user rprice -fstype nfs ! -name /dev/\* -ls | awk '{sum+=$7};\ > {print "User rprice total disk use = " sum}'
3
2107
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 Yahoo!? Yahoo! Mail - Helps protect you from nasty viruses.
16
3945
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 the normal bash commands (e.g. print instead of echo). My main reason for asking is that I like using Python for everything, and if I don't need to learn the bash 'language', then I won't just yet. Thanks.
14
5522
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
3964
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 environment variable. Every time, I've had to go through and add this by hand, to have something resembling a usable Python installation. No such problems on Linux, whether it be Mandrake/Mandriva, Fedora Core, or Kubuntu. So why is the Windows...
24
2839
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 a linux/unix command line guy quite experienced in shell scripts etc. I have a heap of command line utility scripts which I run directly. What is the best way to create python command line scripts but exploit the (loadonly) speed-up benefit of...
7
6236
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 this shell script using the Subprocess module. Here is my code: def resultFromRunning_(command):
0
8921
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
9284
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9202
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
8151
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
6722
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
6022
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
4528
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...
2
2683
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2165
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.