473,698 Members | 2,943 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

running non-python progs from python

hello, i'm fairly new to python programming and programming in general, but
i have written a python prog that creates a MIDI file (.mid) and I want to
be able to play it from another prog which is written in BASIC.
It's a command-line prog that takes the MIDI filename as a parameter and
plays the file.
The 'Learning Python' book talks about using the os.system call, but I
haven't been able to get this to work.
How can I run this other program from a python script and pass the filename
as a parameter?
Jul 18 '05 #1
23 1930
Hi !

You can also do (sample) :

import os
vret = os.popen('c:\\p files\\lplayer. exe')
print vret

@+
--
Michel Claveau


Jul 18 '05 #2
"Spiffy" wrote:
The 'Learning Python' book talks about using the os.system call, but I
haven't been able to get this to work.
"it doesn't work" is a really lousy way to describe a problem what did you
do, what happened, and what did you expect would happen instead?

also see:

http://www.catb.org/~esr/faqs/smart-...ons.html#intro
How can I run this other program from a python script and pass the filename
as a parameter?


import os

filename = "myfile"
os.system("prog ram %s" % filename)

</F>


Jul 18 '05 #3

"Michel Claveau/Hamster" <No********@No. Spam.mclaveau.N o.Spam.com> wrote in
message news:br******** **@news-reader2.wanadoo .fr...
Hi !

You can also do (sample) :

import os
vret = os.popen('c:\\p files\\lplayer. exe')
print vret

@+
--
Michel Claveau
Hello Michel, thanks for taking the time to respond. Unfortunately, when I
tried to run your sample code (changing the name of the file, of course), it
did nothing.

How can I run this other program from a python script and pass the filename as a parameter?
import os

filename = "myfile"
os.system("prog ram %s" % filename)

</F>

Fredrik, the example you provided is virtually the same as the one from the
"Learning Python" book. When I run it, the dos command line appears with the
message 'Bad command or file name". Both the .exe and the .mid file are in
the python path and the spelling has been checked.
What I expected to happen was that the os.system call would start the .exe
and begin playing the .mid file. This does not happen. This is what I meant
when I said I haven't been able to get this to work.
"it doesn't work" is a really lousy way to describe a >problem what did youdo, what happened, and what did you expect would >happen instead?

also see:

http://www.catb.org/~esr/faqs/smartquestions.html#intro


Pardon me for being a newbie, but if you don't have an answer, why do you
have to give me attitude?

Jul 18 '05 #4
"Spiffy" wrote:
How can I run this other program from a python script and pass the filename
as a parameter?


import os

filename = "myfile"
os.system("prog ram %s" % filename)

</F>

Fredrik, the example you provided is virtually the same as the one from the
"Learning Python" book.


that indicates that it's supposed to work, don't you think?
When I run it, the dos command line appears with the message 'Bad command
or file name".
that indicates that Windows cannot find the command, don't you think?
Both the .exe and the .mid file are in the python path and the spelling has
been checked.
you mean sys.path? that's the problem, most likely. As mentioned in the
documentation, os.system() executes the command just as if you've typed
it in a "DOS box". Windows doesn't look at the Python path when you do
that, so to make sure Windows finds the command, you have to add it to
the Windows path (the PATH environment variable), or provide the full path
to os.system().

program = r"x:\full\path\ to\program"
filename = "..."
os.system("%s %s" % (program, filename))

the os.path.abspath () function can be useful in cases like this; it makes sure
that if your program can find a file, another program can also find it:

program = os.path.abspath ("x:/somewhere/program")
filename = os.path.abspath ("somefile")
os.system("%s %s" % (program, filename))

(if the filename may contain spaces, you may have to add quotes around
the second %s)

the relevant manual page contains more information on os.system, and
mentions a couple of alternatives (os.startfile, os.spawnlp, etc):

§http://www.python.org/doc/current/lib/os-process.html
Pardon me for being a newbie, but if you don't have an answer, why do you
have to give me attitude?


os.system() is still the answer; the problem is in how you used it and what
you expected from it, not in the function itself. You cannot expect people
to read your mind, and then complain when they fail.

</F>


Jul 18 '05 #5
Spiffy fed this fish to the penguins on Tuesday 09 December 2003 00:38
am:
from the "Learning Python" book. When I run it, the dos command line
appears with the message 'Bad command or file name". Both the .exe and
the .mid file are in the python path and the spelling has been
checked. What I expected to happen was that the os.system call would
start the .exe and begin playing the .mid file. This does not happen.
This is what I meant when I said I haven't been able to get this to
work.
So include (don't retype or paraphrase, use cut&paste) the /exact/
code which is failing, AND the exact command window output...

Among other things, I don't think os.system() uses the /Python/ path
-- its the equivalent of opening a new command prompt and typing the
command; so it is the OS search path that is used.

Open a command window, and type the exact command you think you are
using in os.system()

-- =============== =============== =============== =============== == <
wl*****@ix.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
=============== =============== =============== =============== == <
Bestiaria Home Page: http://www.beastie.dm.net/ <
Home Page: http://www.dm.net/~wulfraed/ <


Jul 18 '05 #6

"Fredrik Lundh" <fr*****@python ware.com> wrote in message
news:ma******** *************** *************** @python.org...
"Spiffy" wrote:
How can I run this other program from a python script and pass the filename
as a parameter?


import os

filename = "myfile"
os.system("prog ram %s" % filename)

</F>

Fredrik, the example you provided is virtually the same as the one from the "Learning Python" book.


that indicates that it's supposed to work, don't you think?


IT COULD HAVE BEEN A MISPRINT, DON'T YOU THINK?
When I run it, the dos command line appears with the message 'Bad command or file name".


that indicates that Windows cannot find the command, don't you think?
Both the .exe and the .mid file are in the python path and the spelling has been checked.


you mean sys.path?


IF I HAD MEANT sys.path, I WOULD HAVE SAID sys.path, DON'T YOU THINK?

that's the problem, most likely. As mentioned in the documentation, os.system() executes the command just as if you've typed
it in a "DOS box". Windows doesn't look at the Python path when you do
that, so to make sure Windows finds the command, you have to add it to
the Windows path (the PATH environment variable), or provide the full path
to os.system().

program = r"x:\full\path\ to\program"
filename = "..."
os.system("%s %s" % (program, filename))

the os.path.abspath () function can be useful in cases like this; it makes sure that if your program can find a file, another program can also find it:

program = os.path.abspath ("x:/somewhere/program")
filename = os.path.abspath ("somefile")
os.system("%s %s" % (program, filename))

(if the filename may contain spaces, you may have to add quotes around
the second %s)
TYPING THE FULL PATH GIVES ME THE SAME RESULT: NOTHING. THE ABOVE CODE USING
os.path.abspath CAUSES A DOS BOX TO APPEAR AND DO NOTHING WHILE PYTHON
CRASHES. the relevant manual page contains more information on os.system, and
mentions a couple of alternatives (os.startfile, os.spawnlp, etc):

§http://www.python.org/doc/current/lib/os-process.html
Pardon me for being a newbie, but if you don't have an answer, why do you have to give me attitude?
os.system() is still the answer; the problem is in how you used it and

what you expected from it, not in the function itself. You cannot expect people to read your mind, and then complain when they fail.
I DID NOT ASK ANYONE TO READ MY MIND, NOR DID I COMPLAIN THAT ANYONE COULD
NOT READ MY MIND.
I DO NOT THINK THE PROBLEM IS IN HOW I USED THE FUNCTION NOR WHAT I EXPECTED
FROM IT.

Jul 18 '05 #7
Du calme, s'il vous plaît...

--
Michel Claveau
Jul 18 '05 #8

"Dennis Lee Bieber" <wl*****@ix.net com.com> wrote in message
news:ef******** ****@beastie.ix .netcom.com...
Spiffy fed this fish to the penguins on Tuesday 09 December 2003 00:38
am:
from the "Learning Python" book. When I run it, the dos command line
appears with the message 'Bad command or file name". Both the .exe and
the .mid file are in the python path and the spelling has been
checked. What I expected to happen was that the os.system call would
start the .exe and begin playing the .mid file. This does not happen.
This is what I meant when I said I haven't been able to get this to
work.
So include (don't retype or paraphrase, use cut&paste) the /exact/
code which is failing, AND the exact command window output...

Among other things, I don't think os.system() uses the /Python/

path -- its the equivalent of opening a new command prompt and typing the
command; so it is the OS search path that is used.

Open a command window, and type the exact command you think you are using in os.system()

--
> In the command window the call to the program with the name of the .mid
file to be played works just fine. Here is what it looks like....exactly :
C:\Python22>pla yb Canyon.mid

Here is the code used to call it from Python:
import os
filename = "C:\Python22\Ca nyon.mid"
os.system("C:\P ython22\playb.e xe%s"%filename)
....this causes a dos box to appear which promptly hangs and does nothing, at
which time Python stops responding. Vartiations on this will cause the dos
box to appear with the message "Bad command or file name".
=============== =============== =============== =============== == < > wl*****@ix.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
> wu******@dm.net | Bestiaria Support Staff <
> =============== =============== =============== =============== == <
> Bestiaria Home Page: http://www.beastie.dm.net/ <
> Home Page: http://www.dm.net/~wulfraed/ <

Jul 18 '05 #9
> Here is the code used to call it from Python:
import os
filename = "C:\Python22\Ca nyon.mid"
os.system("C:\P ython22\playb.e xe%s"%filename)
...this causes a dos box to appear which promptly hangs and does nothing,
at which time Python stops responding. Vartiations on this will cause the
dos box to appear with the message "Bad command or file name".


Looks like there is a space missing -

os.system("C:\P ython22\playb.e xe %s"%filename)
^

Diez

Jul 18 '05 #10

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

Similar topics

2
7800
by: Rodger Dodger | last post by:
Hi there. We have an application that can run on a non-unicode or a unicode sql server database. Currently the application is running in a unicode database, as a non-unicode database is less than half the size, I would prefer to have a non-unicode database for demo purposes to be on my laptop, etc etc
11
1586
by: John Eskie | last post by:
Lately I've seen alot of C and C++ code (not my own) which doesn't do any checking if memory obtained by new or malloc is valid or if they return NULL pointers. Why does most people not care about doing this kind of error checking? When I used to learn the language I was told always to check "if (p != NULL)" and return a error otherwise. I still do that always but sometimes it's annoying the hell out of me if I want to allocate memory...
29
5804
by: pb648174 | last post by:
I have a very long transaction that runs on the same database that other users need to use for existing data. I don't care if they see data from the transaction before it is done and am only using the transaction because I need a way to roll it back if any errors happen during the transaction. Unfortunately all tables affected in the long running transaction are completely locked and nobody else can access any of the affected tables while...
22
12035
by: Steve - DND | last post by:
We're currently doing some tests to determine the performance of static vs non-static functions, and we're coming up with some odd(in our opinion) results. We used a very simple setup. One class had a static function, and the one class had a non-static function. Both of these functions did the exact same thing. The test function: public void Test(){ decimal y = 2; decimal x = 3;
1
5780
by: Ennio-Sr | last post by:
Hi all! Testing a script where I need to make sure that postgresql is running before passing a <psql dbasename -c "insert into ..." > instruction I faced this curious behaviour: This is the relevant content of the script: ------------------ #!/bin/bash /usr/lib/postgresql/bin/pg_ctl status -D /var/lib/postgres/data >/dev/null 2>&1 rtn=$?
4
1682
by: LurfysMa | last post by:
I could use some help with a table design problem. I have an electronic flashcard program. Actually, several of them. They each rely on a utility program to keep track of the usage statistics. After each practice session, the utility program tells the flashcard program which items were learned and whihc need more practice. The drill stats are trracked by 3 indices: user, subject, and item.
2
6220
by: Tessa | last post by:
Hi, We have a .net web application, and are trying to use PrinterSettings.InstalledPrinters to list the printers installed on the webserver. (Windows 2003 server R2, IIS 6, .net framework 2.0.) The printers installed on the web server under the account used by asp.net for this web application are network printers that are shared by other computers that are on our domain. Permission has been granted for everyone to print to them. The...
13
2939
by: Academic | last post by:
I have a MDI form, sometimes child forms and sometimes forms that are neither If I close the app the child forms closing and closed event happens followed by the Mdi form receiving the events.. But the regular forms that are also open do not receive that event. This is true whether there are child forms open or not.
0
1378
by: jfigueiras | last post by:
>I have a problem with the module subprocess! As many other programs... I'm not sure what you mean by "non-standard file descriptors". The other program is free to open, read, write, etc any file he wants - are you trying to trap any file operation it may want to do? You *could* do such things -google for "code injection" and "API hooking"- but I doubt it's what you really want.
33
11617
by: Sunny | last post by:
Hi, Sometime, when your script is too big, IE Gives you a warning "Stop Running This Script" A script on this page is causing Internet Explorer to run slowly. Does anyone knows, How to correct that? Thanks.
0
8683
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
8610
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
9031
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8902
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
6528
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
4372
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
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
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
3
2007
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.