473,499 Members | 1,648 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to run a python.py script from another python script

2 New Member
I am very new to Python I'm trying to run a python script from within another python script. I can run the script from a unix command line by typing: nohup python script.py password > /tmp/outfile.log 2>&1 & Or, I can put that command in a shell script and run it by typing: ./script.sh Both work great. However I don't know how to put either the command or the shell script in a python.py script and get it to run from there.

Let me know if I need to provide more information.
Mar 29 '10 #1
2 4738
bvdet
2,851 Recognized Expert Moderator Specialist
os.popen() and subprocess.Popen() should do what you need, or you could try importing the second script at required location in the first script.
Mar 29 '10 #2
gintrado
2 New Member
bvdet, thanks for the help. I think I found the problem and it is with crontab and python. I have a python script called scanner.py which I start from the command line and it runs all the time.
Command: nohup python /home/dev/scanner.py password > /tmp/file.log 2>&1 &

Occassionally, the process stops. For that I have another script called check.py which when run checks to see if the scanner.py is running and if not then run the command to start scanner.py, creates a log file and send notification scanner.py is down. When I run this script from the command line it also works.
Command: python /home/dev/check.py > /tmp/check.log

The problem enters when I try to schedule check.py to run every 5 minutes using crontab. Crontab will run every five minutes, a log file is created, I'm notified when the process is down, however, it won't start the scanner.py script like it does when run from command line.
In crontab: */5 * * * * `python /home/dev/check.py > /tmp/check.log 2>&1`

Also, all the scripts have access set to 755.
Apr 6 '10 #3

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

Similar topics

28
4571
by: Erik Johnson | last post by:
This is somewhat a NEWBIE question... My company maintains a small RDBS driven website. We currently generate HTML using PHP. I've hacked a bit in Python, and generally think it is a rather...
3
48750
by: Tubby Tudor | last post by:
What is the best way to call one python script from within another python script? For example: one.py finishes succesfully and calls two.py which finishes OK and then calls three.py Thanks...
52
3697
by: Olivier Scalbert | last post by:
Hello , What is the python way of doing this : perl -pi -e 's/string1/string2/' file ? Thanks Olivier
16
2402
by: Paul Prescod | last post by:
I skimmed the tutorial and something alarmed me. "Strings are a powerful data type in Prothon. Unlike many languages, they can be of unlimited size (constrained only by memory size) and can hold...
10
3658
by: Andrew Dalke | last post by:
Is there an author index for the new version of the Python cookbook? As a contributor I got my comp version delivered today and my ego wanted some gratification. I couldn't find my entries. ...
68
5770
by: Lad | last post by:
Is anyone capable of providing Python advantages over PHP if there are any? Cheers, L.
8
3014
by: Paul Cochrane | last post by:
Hi all, I've got an application that I'm writing that autogenerates python code which I then execute with exec(). I know that this is not the best way to run things, and I'm not 100% sure as to...
0
1444
by: phoolimin | last post by:
Dear all, I am trying to embed python into another scripting language, to do this I need to solve a number of problems on importing or compiling python script. First let me state what exactly I...
2
2141
by: Henry Hollenberg | last post by:
Hello, I have written a script that uses environment variables set during a particular users login in ".bash_profile" and ".profile". I have changed to that users uid and gid in my python...
0
7223
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...
1
6899
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...
0
7390
tracyyun
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...
0
5475
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,...
1
4919
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...
0
4602
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...
0
3103
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...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
302
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...

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.