473,785 Members | 2,807 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to execute a Shell Script in python Codes

1 New Member
Hi,

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

Any Hints

Thanks

Mehdi
Jan 2 '07 #1
2 11068
xrado
8 New Member
Expand|Select|Wrap|Line Numbers
  1. import os
  2. cwd = os.getcwd() # this will get the path you are current in if you need it
  3. os.system('sh script.sh')
Jan 2 '07 #2
bartonc
6,596 Recognized Expert Expert
Hi,

I have a python script which creates a csv file using following method
Expand|Select|Wrap|Line Numbers
  1.  def printOutInformation(self):
  2.         if self.orderby == 'r':
  3.             self.iplist.sort(cmp=self.RealtimeComparison)
  4.         elif self.orderby == 'p':
  5.             self.iplist.sort(cmp=self.ProcessingtimeComparison)
  6.         # by default the order will just be the order that the IPs were in the reasoning log
  7.         if csvoutput:
  8.             csvfile = open(self.csvfile, 'w')
  9.             csvfile.write("IP Address,Total Time Elapsed,Pipeline Processing Time,Start Time,End Time\n")
  10.             for list in self.iplist:
  11.                 ip, realtime, processingtime, starttimestamp, endtimestamp = list
  12.                 csvfile.write("%s,%s,%s,%s,%s\n" % (ip, realtime, processingtime, starttimestamp.isoformat(), endtimestamp.isoformat()))
  13.             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.
Jan 2 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
11017
by: Valentine Kouznetsov | last post by:
Hi, simple question, how to execute command in current shell, not in subshell? Example. I have environment variable A=aaa and need to invoke shell (sh) script which will do something with A. If I do os.system() then sub-shell will setup A and execute my script there leaving A in parent shell untouched. Thanks,
10
2305
by: Daven Nair | last post by:
Hi, I would like to know if Python supports codes similar to shell scripts: count=`ps -ef|grep "pattern"|wc -l` for count in `echo $count` do done fi
6
26182
by: bikkaran | last post by:
Hi . I have to write a Shell script like ... IF "select value from tablnema where condition;" = some_value then depending upon the this value I will call some other script.sql This query will always return 1 value. Can some one help me how to implement this in Shell script.
7
2987
by: spec | last post by:
Hi all, I know nothing about Python. What I need to do is to get a Python script to execute a local shell script. I do not need any output. What would be th eeasiest way to accomplish this? Thanks!
5
7529
by: Chandra | last post by:
Hi, Is there a way to execute a python script(file) in ASP.NET application (programmatically)?? Regards, Chandra
9
78386
by: sohan | last post by:
Hi, I want to know how to connect and execute a db2 query from inside a UNIX shell script. Details: We have a unix shell script. We need to execute multiple db2 sql queries from this shell script and export the result to a file. Any code snippet on this will be helpful.
4
2360
by: brad | last post by:
When I use idle or a shell to execute a python script, the script executes in the directory it is currently in (in this case, my desktop). However, when using GNOME and right clicking the py script and selecting 'open with python', the execution occurs in my home directory, not my desktop. Is there a way to force py scripts to always run within the directory that they reside in? Thanks
3
5453
by: telduivel | last post by:
Can someone please help me with this: I have a python script, that at some point calls a linux bash script (.sh). Starting the shell script is the last thing my python script needs to do, so I would like for the python script to exit once the call has been made, without waiting for the shell script to finish. My question is: how do I call a shell script from a python script? and how do I do that such that control is tranferred to the...
7
6237
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
9645
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
9481
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10336
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10095
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,...
1
7502
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
5383
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...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3655
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.