0

I'm having an issue with "The System cannot find the file specified"

Here is the part of my code that fails:

var processInfo = new ProcessStartInfo("java", javaParam + " -jar " + jar)
        {
            CreateNoWindow = true,
            UseShellExecute = false,
            RedirectStandardOutput = true,
            RedirectStandardInput = true,
            RedirectStandardError = true,
            StandardErrorEncoding = Encoding.UTF8,
            StandardOutputEncoding = Encoding.UTF8,
            WorkingDirectory = _diretory
        };

        Process = new Process { StartInfo = processInfo };
        Process.Start();

In this image. you can see "Arguments" and "WorkingDirectory". my "craftbukkit.jar" is in my working directory. But It can't find it. locals http://bumisworld.eu/locals.png

And here is the error when I run it outside Visual Studio..

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified
   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at The_Bukkit_GUI_Project.MinecraftProcess.StartProcess()
   at The_Bukkit_GUI_Project.Form1.Start()
   at The_Bukkit_GUI_Project.Form1.load_Click(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at Telerik.WinControls.RadControl.OnClick(EventArgs e)
   at Telerik.WinControls.UI.RadButtonBase.buttonElement_Click(Object sender, EventArgs e)
   at Telerik.WinControls.RadItem.OnClick(EventArgs e)
   at Telerik.WinControls.UI.RadButtonItem.OnClick(EventArgs e)
   at Telerik.WinControls.UI.RadButtonElement.OnClick(EventArgs e)
   at Telerik.WinControls.RadItem.DoClick(EventArgs e)
   at Telerik.WinControls.RadItem.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)
   at Telerik.WinControls.RadElement.RaiseRoutedEvent(RadElement sender, RoutedEventArgs args)
   at Telerik.WinControls.RadItem.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)
   at Telerik.WinControls.RadElement.RaiseRoutedEvent(RadElement sender, RoutedEventArgs args)
   at Telerik.WinControls.RadElement.DoMouseUp(MouseEventArgs e)
   at Telerik.WinControls.ComponentInputBehavior.OnMouseUp(MouseEventArgs e)
   at Telerik.WinControls.RadControl.OnMouseUp(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at Telerik.WinControls.RadControl.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

But for some reason. This works on my local computer. But this happens on my remote server. And I have no idea why.. So I'm looking for a little help..

Stian Tofte
  • 213
  • 6
  • 13

1 Answers1

1

First make sure that Java has been installed on the server. Then you should check the following:

If you start a process, it looks for the file name both in the working directory and in the directories listed in the PATH environment variable. Chances are good that on your developer machine the Java-directory has been added to the PATH variable for convinience.

Instead of assigning just java as the executable path, a more stable way is to provide the full path of the executable you want to start.

A - less clean - way to fix this quickly is to change the PATH variable on the server so that the Java-directory is also contained. Nevertheless I'd propose to reference the executable by its full path so that you don't have to change the PATH variable on each computer you want to run your program on.

Markus
  • 20,838
  • 4
  • 31
  • 55
  • Java is installed. When I run "java -jar craftbukkit.jar" from a bat file. It runs fine. And I have tried that with PATH. I got a bit of code getting the location from path. But still no luck with that. – Stian Tofte Apr 21 '14 at 05:52
  • @StianTofte: can you try to reference both Java and the jar in your code with a full path, maybe first Java, then the jar to find out which one is the reason? – Markus Apr 21 '14 at 06:00
  • Well It was Java that it couldn't find for some reason.. When I put the full path to "java.exe". It worked. But now I guess I will have to find a new way to locate java.. – Stian Tofte Apr 21 '14 at 11:13
  • @StianTofte: maybe this question and its answers help: http://stackoverflow.com/questions/3038140/how-to-determine-windows-java-installation-location – Markus Apr 21 '14 at 11:16