473,569 Members | 2,584 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling a dos batch file from python

Suppose I have a batch file called mybatch.bat and I want to run it
from a python script. How can I call this batch file in python script?

Thanx/NSP

Sep 4 '07 #1
3 16326
On Sep 4, 8:42 am, n o s p a m p l e a s e <nospam.ple...@ alum.com>
wrote:
Suppose I have a batch file called mybatch.bat and I want to run it
from a python script. How can I call this batch file in python script?

Thanx/NSP
The subprocess module should work.

Mike

Sep 4 '07 #2
On Sep 4, 5:01 pm, kyoso...@gmail. com wrote:
On Sep 4, 8:42 am, n o s p a m p l e a s e <nospam.ple...@ alum.com>
wrote:
Suppose I have a batch file called mybatch.bat and I want to run it
from a python script. How can I call this batch file in python script?
Thanx/NSP

The subprocess module should work.
Thanx to all those who responded. It was quite simple.

import os
os.system("myba tch.bat")

NSP

Sep 5 '07 #3
I looked into this a little while ago so I could get the MAC address
of a machine while on linux or windows. Here's a simplified version
that just does the windows side;

self.macMatch = re.compile(r"(( \w\w[:-]){5}\w\w)")
data = os.popen("ipcon fig /all", 'r')
text = data.read()
tup = self.macMatch.s earch(text).spa n()
mac = text[tup[0]:tup[1]].replace('-',':')
return mac

This method allows you to catch the text which would normally be
output to the dos window.

Cheers,

Wes.

On 05/09/07, n o s p a m p l e a s e <no***********@ alum.comwrote:
On Sep 4, 5:01 pm, kyoso...@gmail. com wrote:
On Sep 4, 8:42 am, n o s p a m p l e a s e <nospam.ple...@ alum.com>
wrote:
Suppose I have a batch file called mybatch.bat and I want to run it
from a python script. How can I call this batch file in python script?
Thanx/NSP
The subprocess module should work.
Thanx to all those who responded. It was quite simple.

import os
os.system("myba tch.bat")

NSP

--
http://mail.python.org/mailman/listinfo/python-list
Sep 5 '07 #4

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

Similar topics

14
3540
by: Mark C. | last post by:
I'm trying to call a batch file that I've built using the FileSystemObject and CreateObject("Wscript.Shell"), oShell.Run... in an asp script. Naturally, I can get the script to work from a command line but not from a browser. The page does not throw an error but the oShell.Run... portion of the script doesn't run. Any help would be...
0
2565
by: Steve Jorgensen | last post by:
I remember that I used to set up utility batch files, and create Windows shortcuts to them that would ask the user for parameters to supply to the batch files. From what I can tell, this functionality simply doesn't exist anymore in Windows 2000 or above. I did find a work-around to this that I thought y'all might want to know about. ...
4
47460
by: Bill | last post by:
I need help closing a CMD window when it is executed from Access. 1) The batch file is called from Access. 2) Access closes, 3) the batch runs a copy of the access database (creating a backup) 4) Once the copy is complete, the batch file opens the Access database again 5) EXIT should close out the cmd window but it does not execute that...
1
5788
by: Bucky Pollard | last post by:
I have a web service that needs to create a batch file and call it (since there are no APIs for the functionality I am looking for). I am using the Process and ProcessStartInfo objects. When I try to call the batch file, it just returns with a return code of 1. When I call cmd.exe, and pass the batch file as a parameter it hangs. After much...
13
5417
by: MLH | last post by:
I have a batch file named GetConf.bat. It contains a line like this: ipconfig /all >c:\MyAppDir\IPdata.txt I believe I could run the line with something like ShellWait by Terry Kreft. Any reason I should run the procedure via a batch file call as opposed to launching the command string directly?
26
34529
by: mvdkwong | last post by:
What's the trick to running a batch file from VBA? I'm trying to call it using the Shell function but it's not working for me. If I double-click the batch file or run it from the command line it works. I've tried: RetVal = Shell("cmd /c clean.bat", vbNormalFocus) RetVal = Shell("clean.bat", vbNormalFocus) RetVal = Shell("<full...
0
1362
by: gabrielk43 | last post by:
Hi to all, I have made a web service which creates a batch file in a folder in web server and tries to execute it (in a Windows Server 2003 web server). So far I have managed to create the batch file successfully by adjusting the permissions of the folder it is created in, for the user which is assigned to run the web application for the...
1
3128
by: anand18101984 | last post by:
I have a .NET EXE which is called from a batch file. If any error occurs in the EXE, it is not gettign captured in the batch file i.e. batch file always return the errorlevel as 0 irrespective of the error ocurred. Is there any way to throw the error occurred in the .NET EXE and capture it in the batch file?? My batch file looks like below,...
0
1212
by: Roopesh Varma | last post by:
I have a webservice, when executed calls a Batch file (.bat). The batch file looks for certain files in a folder compresses it using 7z.exe and then it has to encrypt using the GPG.exe. However, It does the Compressing part but not the encryption ... any idea? is it coz of some permission issues? if so how come its doing the Compression part? ...
0
7711
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...
0
7628
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...
0
8145
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...
1
7694
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...
0
7993
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...
0
5245
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...
0
3679
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...
0
3667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
970
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...

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.