Link to home
Start Free TrialLog in
Avatar of arichexe
arichexe

asked on

Process Failure

I'm attempting to run the below SQL Server BCP command as a Process, but I'm getting the error, "Unhandled Exception: System.ComponentModel.Win32Exception: The system cannot find the file specified."  What could be causing this?  It runs fine using "Process.Start(Environment.GetEnvironmentVariable("COMSPEC")," /c bcp...", but I want it to wait before exiting; hence, the need for a Process.

Process p = new Process();
p.StartInfo.FileName = "bcp MyDB.dbo.MyTable in MyFile -m 1 -c -S MyServer -U MyUserId -P MyPassword";
p.Start();
p.WaitForExit();
Avatar of dungla
dungla
Flag of Viet Nam image

FileName property must point to a file name with full path and not including parameter
Avatar of arichexe
arichexe

ASKER

How do I specify the parameters?
ASKER CERTIFIED SOLUTION
Avatar of Thandava Vallepalli
Thandava Vallepalli
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here is the sample program


================
using System;

class Demo
{
      public static void Main(string[] args)
      {
            if( args != null && args.Length > 0 )
            {
                  System.Diagnostics.Process proc = new System.Diagnostics.Process();
                  proc.EnableRaisingEvents=false;
                  proc.StartInfo.FileName = args[0];
                  proc.StartInfo.Arguments = (args.Length > 1 ? args[1] : "");
                  proc.Start();
                  proc.WaitForExit();
            }else
            {
                  Console.WriteLine( "Please provide 1 or 2 parameters \n Ex: process notepad (or) process calc" );
            }
      }
}
==============================

compile command: csc <filename.cs>
Execute command:  filename.exe  <processfilepath>  <arguments to the process>

itsvtk