473,748 Members | 2,426 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
23 1936

"Diez B. Roggisch" <de************ @web.de> wrote in message
news:br******** *****@news.t-online.com...
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

There is no space missing. That is the name of the file on my comp.
Jul 18 '05 #11
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 #12
>> > 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

There is no space missing. That is the name of the file on my comp.


Ok, most probably you'll start to yell at me now, but _there is a space
missing_:
filename = "C:\Python22\Ca nyon.mid"
print "C:\Python22\pl ayb.exe%s"%file name

C:\Python22\pla yb.exeC:\Python 22\Canyon.mid

I have no WinBox here - but I bet even windows likes its commandline
arguments somehow separated from each other. Try executing the line above,
and I bet command.com complains about "Bad command or file name".

Diez
Jul 18 '05 #13

"Spiffy" <sp****@worldne t.att.net> wrote in message
news:2f******** *************** @bgtnsc04-news.ops.worldn et.att.net...

"Diez B. Roggisch" <de************ @web.de> wrote in message
news:br******** *****@news.t-online.com...
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

There is no space missing. That is the name of the file on my comp.


The ^ points right after exe. (use fixed fonts to see). The command you are
executing is:

C:\Python22\pla yb.exeC:\Python 22\Canyon.mid

There needs to be a space between exe and the second C:

Hope it helps.
Jul 18 '05 #14

"Diez B. Roggisch" <de************ @web.de> wrote in message
news:br******** *****@news.t-online.com...
> 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

There is no space missing. That is the name of the file on my comp.


Ok, most probably you'll start to yell at me now, but _there is a space
missing_:
filename = "C:\Python22\Ca nyon.mid"
print "C:\Python22\pl ayb.exe%s"%file name

C:\Python22\pla yb.exeC:\Python 22\Canyon.mid

I have no WinBox here - but I bet even windows likes its commandline
arguments somehow separated from each other. Try executing the line above,
and I bet command.com complains about "Bad command or file name".

Diez

....why would i yell at you? you are trying to help and i appreciate that.
Unfortunately, I have tried various spacings both in the filename and the
os.system call and what happens most often is that a dos box appears and
hangs and python stops responding.
Jul 18 '05 #15

"Fedor" <fe***@mailandn ews.com> wrote in message
news:3f******** *************@r eader2.nntp.hcc net.nl...

"Spiffy" <sp****@worldne t.att.net> wrote in message
news:2f******** *************** @bgtnsc04-news.ops.worldn et.att.net...

"Diez B. Roggisch" <de************ @web.de> wrote in message
news:br******** *****@news.t-online.com...
> 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

There is no space missing. That is the name of the file on my comp.


The ^ points right after exe. (use fixed fonts to see). The command you

are executing is:

C:\Python22\pla yb.exeC:\Python 22\Canyon.mid

There needs to be a space between exe and the second C:

Hope it helps.

I have tried your suggestion and put a space after the .exe...the result is
the same as before...a dos box appears and does nothing and python crashes
(stops responding).
Jul 18 '05 #16
Spiffy fed this fish to the penguins on Tuesday 09 December 2003 14:06
pm:

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)
If that is the true statement you are using then it is NOT the same as
the command line shown above... THERE'S NO SPACE BETWEEN PROGRAM and
ARGUMENT!

You are trying to run a file named:

C:\Python22\pla yb.exeC:\Python 22\Canyon.mid
-- =============== =============== =============== =============== == <
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 #17
Spiffy wrote:
that indicates that it's supposed to work, don't you think?
IT COULD HAVE BEEN A MISPRINT, DON'T YOU THINK?


sure. if multiple independent sources say the same thing, your
first thought should be that they're all wrong.
Both the .exe and the .mid file are in the python path and the spelling
been checked.


you mean sys.path?


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


the python path is stored in the sys.path variable. why did you
say python path if you didn't mean it?
I DO NOT THINK THE PROBLEM IS IN HOW I USED THE FUNCTION
NOR WHAT I EXPECTED FROM IT.


no, your problems are obviously elsewhere. good luck with your
programming career.

</F>


Jul 18 '05 #18

"Fredrik Lundh" <fr*****@python ware.com> wrote in message
news:ma******** *************** *************@p ython.org...
Spiffy wrote:
that indicates that it's supposed to work, don't you think?


IT COULD HAVE BEEN A MISPRINT, DON'T YOU THINK?


sure. if multiple independent sources say the same thing, your
first thought should be that they're all wrong.
> Both the .exe and the .mid file are in the python path and the spelling > been checked.

you mean sys.path?


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


the python path is stored in the sys.path variable. why did you
say python path if you didn't mean it?
I DO NOT THINK THE PROBLEM IS IN HOW I USED THE FUNCTION
NOR WHAT I EXPECTED FROM IT.


no, your problems are obviously elsewhere. good luck with your
programming career.

</F>


It's interesting to me that, although you provided no help or answers to me,
you are convinced that you did. In fact, it is clear from your first
response that your intention has been to amuse yourself by spouting attitude
at me. Hope you had a good time. Meanwhile, Fredo has provided a nice answer
that WORKS... along with an explanation of why my code didn't work. He was
HELPFUL and didn't seem to have the need to belittle me for not being a
professional Python Master. You remind me of one of these teens on IRC who
have no other pleasure in life but to sit around and boot people out of
their precious little chat rooms. I imagine if this was IRC, you would have
booted me at the first post.
Jul 18 '05 #19
Dennis Lee Bieber fed this fish to the penguins on Wednesday 10
December 2003 00:31 am:

Talking to myself, again...


Spiffy fed this fish to the penguins on Tuesday 09 December 2003 14:06
pm:

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


What result do you get with just:

os.system("dir" )

-- =============== =============== =============== =============== == <
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 #20

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

Similar topics

2
7803
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
1591
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
5818
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
12046
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
5785
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
1683
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
6224
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
2949
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
1383
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
11631
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
8984
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
8823
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
9530
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...
0
9238
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8237
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6793
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
6073
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
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.