1
\$\begingroup\$

I am trying to make a chess engine run in the background from an interface i designed

    Process stockfish;
        stockfish = new Process {
            StartInfo = new ProcessStartInfo {
                FileName = System.IO.Directory.GetCurrentDirectory () + "\\Assets\\Scripts\\Stockfish\\stockfish.exe",
                Arguments = "",
                UseShellExecute = false,
                RedirectStandardOutput = true,
                RedirectStandardInput = true,
                RedirectStandardError = true,
                CreateNoWindow = true
            }
        };
        try{
            stockfish.Start();
        }
        catch (Exception e) {
            print (e);
        }

The code is throwing an exception

System.ComponentModel.Win32Exception: ApplicationName='E:\Narsun Projects\Ahmad's Projects\CoachChess\Narsun-CoachChess-Unity\Assets\Scripts\Stockfish\stockfish.exe', CommandLine='', CurrentDirectory=''
 at System.Diagnostics.Process.Start_noshell (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process) [0x00000] in <filename unknown>:0 
 at System.Diagnostics.Process.Start_common (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process) [0x00000] in <filename unknown>:0 
 at System.Diagnostics.Process.Start () [0x00000] in <filename unknown>:0 
 at (wrapper remoting-invoke-with-check) System.Diagnostics.Process:Start ()
\$\endgroup\$
5
  • \$\begingroup\$ The callstack shows some problem with the ' in your directory name, you should try a directory without ' \$\endgroup\$ Dec 16, 2016 at 11:19
  • \$\begingroup\$ I think that works \$\endgroup\$ Dec 16, 2016 at 11:32
  • \$\begingroup\$ You removed the ' and it works now? \$\endgroup\$ Dec 16, 2016 at 11:33
  • \$\begingroup\$ When you use a string that has characters like ' or " you should escape them with a \ . You could run a replace function on the directory first (should work like this if it's a String): System.IO.Directory.GetCurrentDirectory().Replace("'","\'") \$\endgroup\$ Dec 16, 2016 at 12:20
  • \$\begingroup\$ Or, you can just mark the string as literal: @"\n\o\e\s\c\a\p\e!" See msdn.microsoft.com/en-us/library/362314fe.aspx \$\endgroup\$
    – 3Dave
    Dec 16, 2016 at 15:06

1 Answer 1

0
\$\begingroup\$

Posting my comment as an answer as it seems to solve the problem.

The callstack shows a problem with the application name :

System.ComponentModel.Win32Exception: ApplicationName='E:\Narsun Projects\Ahmad's Projects\CoachChess\Narsun-CoachChess-Unity\Assets\Scripts\Stockfish\stockfish.exe', CommandLine='', CurrentDirectory=''

You can see that the \Ahmad's Projects\ quote is causing trouble as your program thinks it is the end of the string.

As John Hamilton suggested, you can parse your strings and escape the quote characters directly from your code, but I believe a best practice would be not to put any quoting mark in your directory names to begin with.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .