1,105,644 Community Members

Calling batch files in jython

Member Avatar
potchi
Newbie Poster
10 posts since May 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

How do I call a batch file in jython?

thanks!!

Member Avatar
pyTony
pyMod
6,103 posts since Apr 2010
Reputation Points: 818 [?]
Q&As Helped to Solve: 1,056 [?]
Skill Endorsements: 42 [?]
Moderator
Featured
 
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
>>>
Member Avatar
potchi
Newbie Poster
10 posts since May 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi,

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

is there another way of doing the task??

thanks!!

Member Avatar
vegaseat
DaniWeb's Hypocrite
6,984 posts since Oct 2004
Reputation Points: 1,544 [?]
Q&As Helped to Solve: 1,872 [?]
Skill Endorsements: 67 [?]
Moderator
 
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.

Member Avatar
vegaseat
DaniWeb's Hypocrite
6,984 posts since Oct 2004
Reputation Points: 1,544 [?]
Q&As Helped to Solve: 1,872 [?]
Skill Endorsements: 67 [?]
Moderator
 
1
 

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')
Question Answered as of 2 Years Ago by vegaseat and pyTony
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article