python - Send commands to subprocess.Popen() process -


i need pass commands process on subprocess.popen() when do, works if use stdin.close() afterwards. code below.

sprocess.stdin.write('/stop'.encode()) sprocess.stdin.flush() sprocess.stdin.close() sprocess.stdout.close() 

works, because of stdin.close() , need able without closing pipes.

how can pass commands process without closing pipes after?

#!/usr/bin/python3  import discord import asyncio subprocess import popen, pipe  client = discord.client()  @client.event async def on_ready():     print('bot id: '+ client.user.id +'\nready\n')  @client.event async def on_message(message):     if message.content.startswith('/start'):         if message.channel.name == "server-console":             await client.send_message(message.channel, '**server starting**')             print('server starting')             global sprocess             global soutput             sprocess = popen('java -xmx2048m -xms2048m -jar minecraft_server.jar',                                         shell=true,                                         stdout=pipe,                                         stdin=pipe)      elif message.content.startswith('/stop'):         if message.channel.name == "server-console":             print('server stopping')             sprocess.stdin.write('/stop'.encode())             sprocess.stdin.flush()             sprocess.stdin.close()             sprocess.stdout.close()      elif message.content.startswith('/restart'):         if message.channel.name == "server-console":             print('server restarting')      elif message.content.startswith('/'):         if message.channel.name == "server-console":             sprocess.stdin.write(message.clean_content.encode())             sprocess.stdin.flush()             print(message.clean_content)             print('command sent')  client.run('token') 

note sprocess.stdin.write('/stop'.encode()) not add newline! subprocess expecting line of input, signified either newline or eof. closing stdin send eof.

try sending sprocess.stdin.write('/stop\n'.encode()) instead.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -