Click here to Skip to main content
15,910,886 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to make a GUI for my minecraft server so far i got it to display the output but i come to an error saying
ASM
'java' is not recognized as an internal or external command,
operable program or batch file.

I do not understand this because in another program i made the coding is so simular it should work but it wont? Can someone help me? Thank you in advance

C#
using System;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using Novus_Gui.Properties;

namespace Novus_Gui
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public void button1_Click(object sender, EventArgs e)
        {

            Process ServerProcess = new Process();
            ServerProcess.StartInfo.UseShellExecute = false;
            ServerProcess.StartInfo.FileName = "CMD.exe";
            ServerProcess.StartInfo.Arguments = "/c java -jar Server.jar";
            ServerProcess.StartInfo.CreateNoWindow = true;
            ServerProcess.StartInfo.ErrorDialog = false;
            ServerProcess.StartInfo.RedirectStandardError = true;
            ServerProcess.StartInfo.RedirectStandardOutput = true;
            ServerProcess.StartInfo.RedirectStandardInput = true;
            ServerProcess.Start();
            StreamWriter inputWriter = ServerProcess.StandardInput;
            StreamReader outputReader = ServerProcess.StandardOutput;
            StreamReader errorReader = ServerProcess.StandardError;
            ServerProcess.WaitForExit();
            //Display Outputs
            string displayText = "Output" + Environment.NewLine + "==============" + Environment.NewLine;
            displayText += outputReader.ReadToEnd();
            displayText += Environment.NewLine + "Error" + Environment.NewLine + "==============" +
                           Environment.NewLine;
            displayText += errorReader.ReadToEnd();
            richTextBox1.Text = displayText;
        } 
    }
}
Posted

Try the following:
C#
...
            ServerProcess.StartInfo.FileName = @"c:\Program Files\Java\jre8\bin\java.exe"; // put your own path here
            ServerProcess.StartInfo.Arguments = "-jar Server.jar";
...
 
Share this answer
 
Comments
Yuki24 1-Apr-13 15:11pm    
Ok so this worked But now i have another problem the output only comes out once the java app is closed how do i make it display in real time? also i need to send commands to the java app so i can make the Gui shut the server down using the redirect input

Process ServerProcess = new Process();
ServerProcess.StartInfo.UseShellExecute = false;
ServerProcess.StartInfo.FileName = @"C:\Program Files\Java\jre7\bin\java.exe";
ServerProcess.StartInfo.Arguments = "-jar Server.jar";
ServerProcess.StartInfo.CreateNoWindow = true;
ServerProcess.StartInfo.ErrorDialog = false;
ServerProcess.StartInfo.RedirectStandardError = true;
ServerProcess.StartInfo.RedirectStandardInput = true;
ServerProcess.Start();
StreamWriter inputWriter = ServerProcess.StandardInput;
StreamReader errorReader = ServerProcess.StandardError;
ServerProcess.WaitForExit();
string displayText = Environment.NewLine;
displayText += errorReader.ReadToEnd();
richTextBox1.Text = displayText;
Garth J Lancaster 1-Apr-13 19:41pm    
How are you reading (for example) the redirected standard out (it doesnt look like you are btw, looking at that code fragment) .. I would redirect standard out, and have a background worker reading the ?stream, sending the data back to a queue/listbox/other ui item .. Im sure if you serach around here on CP there are articles where people have redirected a processes' standard out and captured it...
Either as Mehdi says, or, put the path to java in your system path (this is usually done as part of the jre install) .. to check that its in the path, bring up a command/dos prompt, and type

java -version

if you get an error the path is incorrect

'g'
 
Share this answer
 
v2
Comments
Yuki24 1-Apr-13 15:12pm    
this helped otherwise that code wouldnt have worked thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900