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.Win3 2Exception : The system cannot find the file specified." What could be causing this? It runs fine using "Process.Start(Environment .GetEnviro nmentVaria ble("COMSP EC")," /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();
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();
FileName property must point to a file name with full path and not including parameter
ASKER
How do I specify the parameters?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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=f alse;
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
================
using System;
class Demo
{
public static void Main(string[] args)
{
if( args != null && args.Length > 0 )
{
System.Diagnostics.Process
proc.EnableRaisingEvents=f
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