473,394 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How do you execute external programs from Python?

Hi,

I have this little code snippet that I use for recording audio streams. My
problem is that I want to schedule my recordings with crontab. This does
not work, however. I cannot figure out why; my code works fine when run
manually from the command prompt.

On final thing: What would be the best way to turn off the recording?

Can someone help me?

Carl
Here is my code:

import time
import os
import shutil

URL = "http://www.jazzandblues.org/listen/links/kkjz1.ram"

def RecordURL(what = "KKJZ"):
str_mplayer = "mplayer -playlist " + URL
str_mplayer += " -ao pcm -aofile "
str_mplayer += what + ".wav" + " -vc dummy -vo null"
os.system(str_mplayer)

def CreateOGG(what = "KKJZ"):
ogg_file = what + ".ogg"
str_oggenc = "oggenc " + what + ".wav"
os.system(str_oggenc)

def CreateMP3(what = "KKJZ"):
mp3_file = what + ".mp3"
str_lame = "lame " + what + ".wav " + mp3_file
os.system(str_lame)

def DeleteWAV(what = "KKJZ"):
wav_file = what + ".wav"
str_rm = "rm " + wav_file
os.system(str_rm)

def DateTag(what = "KKJZ"):
local_time = time.asctime(time.localtime())
for local_file in [ what + ".ogg", what + ".mp3" ]:
length = len(local_file)
local_file_copy = local_file[: length - 4] + "_" + local_time + "."
+ local_file[length - 3 :]
shutil.copy(local_file, local_file_copy)

RecordURL()
## CreateOGG()
## CreateMP3()
## DeleteWAV()
## DateTag()

Here is my crontab entry:

30 * * * * python -c "import os; os.chdir('/home/alpha/mymusic/P2/Jazz/');
import KKJZ"
Jul 18 '05 #1
4 4127

You did not mentions what specific part is not working under cron, so
here is a guess.

Maybe the PATH environment variable is not set correctly such that
binaries like mplayer can not be found.

Try using absolute path names for mplayer and any other files.

/Jean Brouwers
In article <iGppd.2045$3N5.117@amstwist00>, Carl
<ph***********@chello.se> wrote:
Hi,

I have this little code snippet that I use for recording audio streams. My
problem is that I want to schedule my recordings with crontab. This does
not work, however. I cannot figure out why; my code works fine when run
manually from the command prompt.

On final thing: What would be the best way to turn off the recording?

Can someone help me?

Carl
Here is my code:

import time
import os
import shutil

URL = "http://www.jazzandblues.org/listen/links/kkjz1.ram"

def RecordURL(what = "KKJZ"):
str_mplayer = "mplayer -playlist " + URL
str_mplayer += " -ao pcm -aofile "
str_mplayer += what + ".wav" + " -vc dummy -vo null"
os.system(str_mplayer)

def CreateOGG(what = "KKJZ"):
ogg_file = what + ".ogg"
str_oggenc = "oggenc " + what + ".wav"
os.system(str_oggenc)

def CreateMP3(what = "KKJZ"):
mp3_file = what + ".mp3"
str_lame = "lame " + what + ".wav " + mp3_file
os.system(str_lame)

def DeleteWAV(what = "KKJZ"):
wav_file = what + ".wav"
str_rm = "rm " + wav_file
os.system(str_rm)

def DateTag(what = "KKJZ"):
local_time = time.asctime(time.localtime())
for local_file in [ what + ".ogg", what + ".mp3" ]:
length = len(local_file)
local_file_copy = local_file[: length - 4] + "_" + local_time + "."
+ local_file[length - 3 :]
shutil.copy(local_file, local_file_copy)

RecordURL()
## CreateOGG()
## CreateMP3()
## DeleteWAV()
## DateTag()

Here is my crontab entry:

30 * * * * python -c "import os; os.chdir('/home/alpha/mymusic/P2/Jazz/');
import KKJZ"

Jul 18 '05 #2
> > Here is my crontab entry:

30 * * * * python -c "import os; os.chdir('/home/alpha/mymusic/P2/Jazz/');
import KKJZ"


Hi,

if cron is running as root say

30 * * * * "su - user; script.sh"

su - user means that .profile, .bash-profile etc is read. I think its
an "Environmental" Problem
Jul 18 '05 #3
Carl wrote:
Hi,

I have this little code snippet that I use for recording audio streams. My
problem is that I want to schedule my recordings with crontab. This does
not work, however. I cannot figure out why; my code works fine when run
manually from the command prompt.

On final thing: What would be the best way to turn off the recording?

Can someone help me?

Carl
Here is my code:

import time
import os
import shutil

URL = "http://www.jazzandblues.org/listen/links/kkjz1.ram"

def RecordURL(what = "KKJZ"):
str_mplayer = "mplayer -playlist " + URL
str_mplayer += " -ao pcm -aofile "
str_mplayer += what + ".wav" + " -vc dummy -vo null"
os.system(str_mplayer)

def CreateOGG(what = "KKJZ"):
ogg_file = what + ".ogg"
str_oggenc = "oggenc " + what + ".wav"
os.system(str_oggenc)

def CreateMP3(what = "KKJZ"):
mp3_file = what + ".mp3"
str_lame = "lame " + what + ".wav " + mp3_file
os.system(str_lame)

def DeleteWAV(what = "KKJZ"):
wav_file = what + ".wav"
str_rm = "rm " + wav_file
os.system(str_rm)

def DateTag(what = "KKJZ"):
local_time = time.asctime(time.localtime())
for local_file in [ what + ".ogg", what + ".mp3" ]:
length = len(local_file)
local_file_copy = local_file[: length - 4] + "_" + local_time +
"."
+ local_file[length - 3 :]
shutil.copy(local_file, local_file_copy)

RecordURL()
## CreateOGG()
## CreateMP3()
## DeleteWAV()
## DateTag()

Here is my crontab entry:

30 * * * * python -c "import os; os.chdir('/home/alpha/mymusic/P2/Jazz/');
import KKJZ"


Thanks guys!

It was an environmental problem. It works now; the only thing I still
haven't solved is how to kill the spawned process after say an hour. Any
clues?

Carl

Jul 18 '05 #4
"Carl" <ph***********@chello.se> wrote in message
news:e_1qd.2176$3N5.2001@amstwist00...
Carl wrote:

Thanks guys!

It was an environmental problem. It works now; the only thing I still
haven't solved is how to kill the spawned process after say an hour. Any
clues?

Carl


Have you investigated...?

os.spawn*()
os.P_NOWAIT
os.kill()
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Krisztian Kepes | last post by:
Hi ! I want to start many py programs - with other parameters. Because the programs have many to-do, I don't want to wait for them. In Delphi it is like this: >>>>>>>>>>>>>>>
17
by: David Hughes | last post by:
For example, in Python in a Nutshell, Alex Martelli shows how you can run a Windows (notepad.exe) or Unix-like (/bin/vim) text editor using os.spawnv(os.P_WAIT, editor, ) But how would you call...
8
by: Greg Fierro | last post by:
I would appreciate any help from anyone with the following: I have an external program (window32 based) that I am executing with the VBA SHELL command. This program produces a text file which I...
4
by: Tom | last post by:
Hi, I wrote a java console program. But, I am not familiar with Swing to write the GUI. I want to use C# to write the GUI, e.g. a start and a stop buttons. When I click the start button, it...
12
by: John F. | last post by:
Here is my code; Dim psi As New System.Diagnostics.ProcessStartInfo psi.UseShellExecute = True psi.FileName = "C:\WinProg.exe" System.Diagnostics.Process.Start(psi) Have tested WinProg.exe...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
4
by: =?Utf-8?B?TEJU?= | last post by:
Good day, I would like to execute an external application from a web form created using ASP.Net. I'm using System.Diagnostics.Process. It works fine if it is notepad.exe but it is not able to...
7
by: Brian Erhard | last post by:
I am still fairly new to python and wanted to attempt a home made password protection program. There are files that I carry on a USB flash drive that I would like to password protect. ...
1
by: Marty | last post by:
I need to catch exceptions thrown by programs started by the os.system function, as indicated by a non-zero return code (e.g. the mount utility). For example, if I get the following results in a...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
0
BarryA
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...
0
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,...
0
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,...
0
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...
0
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
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...

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.