How to execute a Shell Script in python Codes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mesum98
    New Member
    • Jan 2007
    • 1

    #1

    How to execute a Shell Script in python Codes

    Hi,

    I have a python script which creates a csv file using following method
    Code:
     def printOutInformation(self):
            if self.orderby == 'r':
                self.iplist.sort(cmp=self.RealtimeComparison)
            elif self.orderby == 'p':
                self.iplist.sort(cmp=self.ProcessingtimeComparison)
            # by default the order will just be the order that the IPs were in the reasoning log
            if csvoutput:
                csvfile = open(self.csvfile, 'w')
                csvfile.write("IP Address,Total Time Elapsed,Pipeline Processing Time,Start Time,End Time\n")
                for list in self.iplist:
                    ip, realtime, processingtime, starttimestamp, endtimestamp = list
                    csvfile.write("%s,%s,%s,%s,%s\n" % (ip, realtime, processingtime, starttimestamp.isoformat(), endtimestamp.isoformat()))
                csvfile.close()
    I want to run the additional shell script once the above csv file has been generated.

    Any Hints

    Thanks

    Mehdi
    Last edited by bartonc; Jan 2 '07, 08:48 PM. Reason: added [code][/code] tags
  • xrado
    New Member
    • Dec 2006
    • 8

    #2
    Code:
    import os
    cwd = os.getcwd() # this will get the path you are current in if you need it
    os.system('sh script.sh')

    Comment

    • bartonc
      Recognized Expert Expert
      • Sep 2006
      • 6478

      #3
      Originally posted by mesum98
      Hi,

      I have a python script which creates a csv file using following method
      Code:
       def printOutInformation(self):
              if self.orderby == 'r':
                  self.iplist.sort(cmp=self.RealtimeComparison)
              elif self.orderby == 'p':
                  self.iplist.sort(cmp=self.ProcessingtimeComparison)
              # by default the order will just be the order that the IPs were in the reasoning log
              if csvoutput:
                  csvfile = open(self.csvfile, 'w')
                  csvfile.write("IP Address,Total Time Elapsed,Pipeline Processing Time,Start Time,End Time\n")
                  for list in self.iplist:
                      ip, realtime, processingtime, starttimestamp, endtimestamp = list
                      csvfile.write("%s,%s,%s,%s,%s\n" % (ip, realtime, processingtime, starttimestamp.isoformat(), endtimestamp.isoformat()))
                  csvfile.close()
      I want to run the additional shell script once the above csv file has been generated.

      Any Hints

      Thanks

      Mehdi
      Hello, Mehdi. I've added CODE tags to your post to make it readable. You will learn how to do this as we go along. Instructions are in "Posting Guidelines" in several places on this forum. Also, We need to know which operating system you are on, in order to give the correct information.

      Comment

      Working...