We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,991 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Calling batch files in jython

How do I call a batch file in jython?

thanks!!

3
Contributors
4
Replies
1 Day
Discussion Span
2 Years Ago
Last Updated
5
Views
Question
Answered
potchi
Newbie Poster
10 posts since May 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Here test, subprocess module functions OK in Jython, as it should:

Test batch file batch.bat

@echo off
echo Hello, from batch file

Test in Jython prompt:

>>> import subprocess
>>> subprocess.call("batch.bat")
Hello, from batch file
0
>>>
pyTony
pyMod
Moderator
6,305 posts since Apr 2010
Reputation Points: 879
Solved Threads: 986
Skill Endorsements: 26

Hi,

I'm getting the error
InputError: no module named subprocess

is there another way of doing the task??

thanks!!

potchi
Newbie Poster
10 posts since May 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

You might want to update to the latest version of Jython. This one works just fine on my Windows7 machine ...

"""jy_hello_bat.py
run a batch file using Jython

The Windows batch file 'hello.bat' is:
echo Hello, from batch file 

tested with jython2.5.2
"""

import subprocess

subprocess.call('hello.bat')

In my experience most of my normal Python26 code seems to work with Jython 2.5.2 as well.
Jython is actually a real nice way for Java programmers to enjoy Python syntax, and for Python programmers to get used to a little Java.

vegaseat
DaniWeb's Hypocrite
Moderator
6,475 posts since Oct 2004
Reputation Points: 1,447
Solved Threads: 1,611
Skill Endorsements: 36

This might be simpler ...

"""jy_hello_bat2.py
run a batch file using Jython

The Windows batch file 'hello.bat' is:
echo Hello, from batch file 

tested with jython2.5.2
"""

import os

os.system('hello.bat')
vegaseat
DaniWeb's Hypocrite
Moderator
6,475 posts since Oct 2004
Reputation Points: 1,447
Solved Threads: 1,611
Skill Endorsements: 36
Question Answered as of 1 Year Ago by vegaseat and pyTony

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.2971 seconds using 2.77MB