This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-01-05 12:50:43

drhelmi
Scratcher
Registered: 2008-10-01
Posts: 100+

Python problem

Hi all. I am working on a python script to manage a minecraft server. I would like to be able to open the server in a new command window, and when you stop it, it will not close the python window as well. I have extensively googled it, to no avail. Here is what I have so far.

Code:

import subprocess 
p = subprocess.Popen(args=['java', '-jar', 'minecraft_server.jar', 'nogui'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
print p.stderr.read()
print p.stdout.read()

The problem is, I am able to enter commands, but there is no output. I have also tried.

Code:

import subprocess
subprocess.call(['java', '-jar', 'minecraft_server.jar', 'nogui'])

This outputs, and functions normally, except that it outputs into the python window. Thanks.

Offline

 

#2 2012-01-07 14:31:59

drhelmi
Scratcher
Registered: 2008-10-01
Posts: 100+

Re: Python problem

Bump. Nobody?

Offline

 

#3 2012-01-07 14:34:20

777w
Scratcher
Registered: 2009-02-10
Posts: 1000+

Re: Python problem

drhelmi wrote:

Bump. Nobody?

bro dont bump after like 3 seconds
thats annoying

Offline

 

#4 2012-01-07 14:34:59

imnotbob
Scratcher
Registered: 2010-12-11
Posts: 1000+

Re: Python problem

777w wrote:

drhelmi wrote:

Bump. Nobody?

bro dont bump after like 3 seconds
thats annoying

How was that 3 seconds???
More like 2 days xP

Last edited by imnotbob (2012-01-07 14:35:19)


PesterChum Handle: annoyingAnchorman
durp yo terezi sup sup gotta beat john gotta beat john

Offline

 

#5 2012-01-07 14:36:31

777w
Scratcher
Registered: 2009-02-10
Posts: 1000+

Re: Python problem

imnotbob wrote:

777w wrote:

drhelmi wrote:

Bump. Nobody?

bro dont bump after like 3 seconds
thats annoying

How was that 3 seconds???
More like 2 days xP

oh was it
oh sorry i thought it was posted like today

Offline

 

#6 2012-01-07 14:37:14

imnotbob
Scratcher
Registered: 2010-12-11
Posts: 1000+

Re: Python problem

777w wrote:

imnotbob wrote:

777w wrote:


bro dont bump after like 3 seconds
thats annoying

How was that 3 seconds???
More like 2 days xP

oh was it
oh sorry i thought it was posted like today

lol no
Oh well
drhelmi got a nice warning for the future.


PesterChum Handle: annoyingAnchorman
durp yo terezi sup sup gotta beat john gotta beat john

Offline

 

#7 2012-01-07 15:27:20

GameHutSoftware
Scratcher
Registered: 2010-04-24
Posts: 1000+

Re: Python problem

goes in AT


Lurking more than posting, but still here.

Offline

 

#8 2012-01-08 04:23:20

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: Python problem

I tried to do this before, with the same problem as you. Here's as far as I got:

Code:

process = subprocess.Popen('java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui', shell='/bin/bash', stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

I think you should then be able to read the output straight into Python with:

Code:

process.stdout.read()

...but that didn't work for me. Let me know if it does...

That's probably as close as you can get; if you really need a separate command window, you could create one in Python using something like Tkinter and send all the output there.

Hope that helps a little  smile


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

Board footer