0

I have a .bat file that launches a command, I would like to do away with using a .bat file and programmatically start the process in C#.

Here is the .bat command line

start ShooterGameServer.exe TheIsland?QueryPort=27015?SessionName=ARKServer?MaxPlayers=5?listen?ServerPassword=55555?ServerAdminPassword=55555 -nosteamclient -game -server -log

I tried setting it up like this in C#

Process.Start("CMD.exe", string.Format("Start {0} TheIsland?QueryPort=27015?SessionName?{1}?MaxPlayers={3}?listen?ServerPassword={2}?ServerAdminPassword={2} -nosteamclient -game -server -log", ArkServer.FileName, textBox1.Text, textBox2.Text, numericUpDown1.Value.ToString()));

All I end up with after running that command in C# is a cmd window with this printed on it

C:\Users\*******\Documents\Visual Studio 2013\Projects\ArkProfileEditor\ArkProfi
leEditor\bin\Debug>

3 Answers 3

1

I think what you meant to do was launch the exe and not the command window. Try the following

Process.Start("ShooterGameServer.exe", string.Format("TheIsland?QueryPort=27015?SessionName?{1}?MaxPlayers={3}?listen?ServerPassword={2}?ServerAdminPassword={2} -nosteamclient -game -server -log", ArkServer.FileName, textBox1.Text, textBox2.Text, numericUpDown1.Value.ToString()));

Make sure that ShooterGameServer.exe is in the same directory as the exe launching it or pass an appropriate path.

Sign up to request clarification or add additional context in comments.

Comments

1
            SaveFileDialog saveserver = new SaveFileDialog();
        saveserver.FileName = "ARKServerStart.bat";
        saveserver.Filter = "ARKServerStart (*.bat)|*.bat";
        saveserver.InitialDirectory = ArkServer.FileName;
        if (saveserver.ShowDialog() == DialogResult.OK)
        {
            StreamWriter SW = new StreamWriter(saveserver.FileName);
            string runit = string.Format("start ShooterGameServer.exe TheIsland?QueryPort=27015?SessionName={0}?MaxPlayers={3}?listen?ServerPassword={1}?ServerAdminPassword={2} -nosteamclient -game -server -log", ServName.Text, ServPass.Text, AdmnPass.Text, MPlayers.Value.ToString(), ArkProfile.FileName.Replace("ShooterGameServer.exe", ""));
            SW.WriteLine(runit);
            SW.Close();
            var dir = new ProcessStartInfo();
            Path.GetDirectoryName(saveserver.FileName);
            dir.WorkingDirectory = Path.GetDirectoryName(saveserver.FileName);
            dir.FileName = saveserver.FileName;
            dir.CreateNoWindow = true;
            Process pro = Process.Start(dir);
            Clipboard.SetText(saveserver.FileName);
        }

This is the code I ended up with for the final product :) it works great! Hopefully it helps someone else who needs it.

Comments

0

cmd.exe does not take arguments like that.

You want to run cmd /c ... to tell cmd to run that command.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.