Converting a bash script to python (small script) -


I have a script used for a clerical environment, but now I have to use it on the Windows platform and I I would like to convert the Bash script to Python script which I can run.

The Bash script is simple (I think) and I have tried to convert it through Google, but can not change it successfully.

The Bash script looks like this:

  runs = 5 queries = 50 outfile = outputfile.txt Date & gt; & Gt; $ Outfile echo-e "\ n ---------------------------------" echo -e "\ n-- --------- General -------------- "echo-e" \ n ------------------- -------------- "echo-e" \ n ----------- General -------------- "& gt; ; & Gt; For $ Outfile ((R = 1; R & lt; ($ run + 1); r ++) Echo-A "run $ run $ r \ n" db2 flush package cache dynamic python reads.py -r1 - Pquery1 sql -q $ queries- shotelspec -k6 -a5 & gt; & Gt; $ Outfile  

The main command, the Python read.py ... is another Python file that I have been given and as you are looking at the logic.

I know that there is a lot to ask for, but it will really help me if someone can convert it to a Python script which I can use or at least sign me some And I can give instructions.

Honesty

Mastica

Added per request:

This is what I wrote but without success:

< Pre> runs = 5 questions = 50 outfile = redesigntext file = open ("results.txt", "ab") print "\ n ------------------ --------- ------ "print" \ n ----------- General -------------- "Print" \ N -------- ------------------------- "file.write (" \ n -------- --- General ----- --------- \ n ") Print" \ n ------------- Without index --------- ----- File "file. To write ("\ n ------------- Unf indexed questions -------------- \ n") r = 1; R & lt; (% S + 1); R ++% Run Runs% s of% s Run \ n "% r% Run DB2 Flush Hap Package Cache Dynamic Output = Python reads.py -r1 -pquery1.sql -q $ queries -shotelspec -k6 -a5 file .write (output) File.close ()

Closing your program is quite easy Only the hard part DB2 command will be running and (perhaps) refactoring reads.py so that it can be called the library function.

The basic idea is the same:

  • Setting up local variables is similar.
  • Guna Change with print .
  • For your loop in the category: .
  • date with the module.
  • Type the file with the module. / Li>
  • Call the code with the db2
  • You will need to use reads.py as a library to import (or you can use subprocess).
  • < / Ul>

    But, as Marcello says, if come Paco needs more help - so you directly ask questions directly to ask yourself some questions.


Comments