'C# is unable to create a process and call a R script by that process

My c# code

public static string RunRScript(string filePath, string rScriptExecutablePath, string args, int totalFiles,
            int RowsInChunk, int TotalRows, string identity)
        {
            string rCodeFilePath = filePath; //RScriptPath.GetFilePath();
            //string file = rCodeFilePath;
            string result = string.Empty;


          
            // IEnumerable<string> connections = _connections.GetConnections(identity)
            try
            {

                var info = new ProcessStartInfo();
                info.FileName = rScriptExecutablePath;  
                info.WorkingDirectory = Path.GetDirectoryName(rScriptExecutablePath);
                info.Arguments = "\"" + rCodeFilePath + "\"" + " " + args;

                info.RedirectStandardInput = false;
                info.RedirectStandardOutput = true;
                info.UseShellExecute = false;
                info.CreateNoWindow = true;

                string fileName = string.Empty;
                DateTime startTime = DateTime.Now;

                List<ProgressTracker> lstProgress = new List<ProgressTracker>();
                ProgressTracker p;
                using (var proc = new Process())
                {
                    //proc.StartInfo.Verb = "runas";
                    for (int i = 1; i <= totalFiles; i++)
                    {
                        p = new ProgressTracker();
                        p.DT = DateTime.Now;
                        p.Progress = i;
                        lstProgress.Add(p);

                        info.Arguments = "\"" + rCodeFilePath + "\"" + " " + args + " " + i.ToString();
                        proc.StartInfo = info;
                        proc.Start();

                        proc.WaitForExit();

                        result = proc.StandardOutput.ReadToEnd();
                        p.TimeTaken = (DateTime.Now - p.DT).TotalSeconds;
                      


                        Functions.SendProgress("Process in progress...", i, totalFiles, RowsInChunk, TotalRows, lstProgress, identity);

                    }
                }
                return FormatOutput(result);
            }
            catch (Exception ex)
            {
                throw new Exception("R Script failed: " + result, ex);
            }
        }

Now objects have values like

info.FileName = C:\Program Files\R\R-3.4.3\bin\Rscript.exe

info.WorkingDirectory = C:\Program Files\R\R-3.4.3\bin

info.Arguments = "C:\MANOJ R\Topic modelling v2\TM_Webapi\Honeywell.UOP.TopicModel.Api\Uploads\h481821\TopicSearch.R" h481821 1

But process is not creating and its not calling R script and even it doesn't throwing any exception

Even I tried running VS as admin but no luck!



Solution 1:[1]

I have changed the .exe file path from

C:\Program Files\R\R-3.4.3\bin\Rscript.exe
to
C:\Program Files\R\R-3.4.3\bin\x64\Rscript.exe

Since I am using 64 bit machine

Now the process is working

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Manoj R