Hello evryone
I am a newbie to python. I have a makefile which i can compile in
UNIX/LINUX, But i
I am planning to write a python script which actually does what my
MAKEFILE does. The make file is
#Makefile and some scripts to give output
#numbers
#Change till sign #END
var1:=564-574
a1 = 23
b1 = 678
kxm = ixm_7.gh
out = c$(var1)_s.gh
imageim
#END
#other files
file1 = sec$(b1).jk
file2 = sgf$(a1)
file3 = p$(b1).gh
prg3scriptfile = prg3_produce.xx
findoutdir = Dir:~/home/
x=67
#work
evrything: prg1 script2 prg3 script4
withoutprg1: script2 prg3 script4
prg1:
s$(ca)$(d) .
script2: Makefile
./script2 -i '$(file2)' -o '$(file1)' -a $(x) -n
prg3:
: > $(prg3scriptfile) $(prg3scriptfile)
prg3 $(prg3scriptfile)
rm $(prg3scriptfile)
script4:
./script4 $(kxm) $(file2) $(out) $(var1)
I want to write a python script to replace this Makefile.
I Have tried using getopt/optparse for parsing command line options
How to Run Unix shell command from python.
My Task is
Myprg.py a1 b1 kxm out
Kindly suggest me some ideas/comments.
Thanks
koid wayne 4 4044
Thanks for your reply
I started writing the script.. I have gone through documentation for
getopt
import string, getopt, sys
def usage():
print '''myscript.py -- uses getopt to recognize options
Options: -n -- No
-t -- T
-h -- help
-i -- i
-o -- Output:filename'''
sys.exit(1)
def main():
print "SYS ARGV: ", ",".join(sys.argv)
# Define the Options
Options = {
'n:': 'Number=',
't:': 'T',
'h' : 'help',
'i' : 'i',
'o' : 'Output_file',
}
shortOpts = ''.join(Options.keys())
longOpts = Options.values()
try:
(opts, args) = getopt.getopt(argv[1:], shortOpts, longOpts)
except getopt.error, msg:
print "Unrecognized argument or option"
# end try
for (opt, arg) in opts:
if opt in ('-n', '--Number'):
print '-n is the Number', Number
sys.exit()
elif opt in ('-t', '--T'):
print '-t is the T', T
sys.exit()
elif opt in ('-h', '--help'):
usage()
print " "
sys.exit()
elif opt in ('-i', '--i'):
print " I", i
elif opt in ('-o', '--Output Filename'):
print "Output", Output
# end if
# end for
print "OPTS: ", ",".join([repr(o) for o in opts])
print "ARGS: ", ",".join(args)
if __name__ == "__main__":
main()
with the above code, I am planning to do command line parsing. But how
to run unix shell command? DO i have to use os Module/ import command?
How should i proceed further, to
import commands
commands.getstatusoutput('ls /bin/ls')
Please suggest me some ideas how to proceed further
Thanks
On 22 Apr 2005 03:16:02 -0700, hue <pr*********@gmail.com> wrote: Thanks for your reply I started writing the script.. I have gone through documentation for getopt
(snip)
Good start. I tend to prefer optparse over getopt these days, but if
you've got it working the way you want it, you should probably stick
with what you have.
with the above code, I am planning to do command line parsing. But how to run unix shell command? DO i have to use os Module/ import command? How should i proceed further, to import commands commands.getstatusoutput('ls /bin/ls')
You'll certainly need to import *something*. Have you looked at the
subprocess module?
--
Cheers,
Simon B, si***@brunningonline.net, http://www.brunningonline.net/simon/blog/
On Friday 22 April 2005 01:39 am, rk****@yahoo.com wrote: I am a newbie to python. I have a makefile which i can compile in UNIX/LINUX, But i I am planning to write a python script which actually does what my MAKEFILE does. The make file is
[...] I want to write a python script to replace this Makefile. I Have tried using getopt/optparse for parsing command line options How to Run Unix shell command from python.
Read the documentation on the "os" and "popen2" modules under
"generic operating system services" in the Python Standard Library
Manual (go to http://www.python.org if you haven't already got this
manual on hand).
Cheers,
Terry
--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks http://www.anansispaceworks.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Paddy McCarthy |
last post by:
This is really a comment on "Python in Systems Administration: Part I
-- Better Scripting"
http://www.samag.com/documents/s=8964/sam0312a/0312a.htm
by Cameron Laird.
Reading the article,...
|
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...
|
by: dean |
last post by:
Hello Group:
Hopefully someone can answer my question.
I have a unix shell command that I would like to emulate in python. I
am sanning a file that contains a stream of data with a record size...
|
by: Jeff Wagner |
last post by:
I have a project of converting numerous DOS cmd shell scripts to Python. Is there a tutorial to
getting started?
Thanks, Jeff
|
by: John Salerno |
last post by:
Here's my new project: I want to write a little script that I can type
at the terminal like this:
$ scriptname package1
where scriptname is my module name and any subsequent arguments are the...
|
by: Ignoramus6539 |
last post by:
There were some strange requests to my server asking for config.php
file (which I do not have in the requested location).
I did some investigation. Seems to be a virus written in perl,...
|
by: Anastasios Hatzis |
last post by:
I'm looking for a pattern where different client implementations can use the
same commands of some fictive tool ("foo") by accessing some kind of API.
Actually I have the need for such pattern for...
|
by: Tom Gur |
last post by:
Hi,
It's seems that csh and tcsh acts a bit different when handling
special characters in quotes.
i.e: if i'll supply my program with the following arguments: -winpath
"c:\\temp\\"
tcsh will...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
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...
|
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: 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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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: 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...
| |