Hello,
How to display list process, when i run sql*loader in c#. I mean when i run sql*loader from cmd windows, i get list process how many row has been inserted. But when i run SQL*Loader from C#, i can't get process SQL*Loader.
This is my code:
string strCmd, strSQLLoader;
string strLoaderFile = "XLLOAD.CTL";
string strLogFile = "XLLOAD_LOG.LOG";
string strCSVPath = @"E:\APT\WorkingFolder\WorkingFolder\sqlloader\sqlloader\bin\Debug\8testskrip_HTTP.csv";
string options = "OPTIONS (SKIP=1, DIRECT=TRUE, ROWS=1000000,BINDSIZE=512000)";
string append = "APPEND INTO TABLE XL_XDR FIELDS TERMINATED BY ','";
string table = "OPTIONALLY ENCLOSED BY '\"' TRAILING NULLCOLS (xdr_id,xdr_type,session_start_time,session_end_time,session_last_update_time,session_flag,version,connection_row_count,error_code,method,host_len,host,url_len,url,connection_start_time,connection_last_update_time,connection_flag,connection_id,total_event_count,tunnel_pair_id,responsiveness_type,client_port,payload_type,virtual_type,vid_client,vid_server,client_addr,server_addr,client_tunnel_addr,server_tunnel_addr,error_code_2,ipid,c2s_pkts,c2s_octets,s2c_pkts,s2c_octets,num_succ_trans,connect_time,total_resp,timeouts,retries,rai,tcp_syns,tcp_syn_acks,tcp_syn_resets,tcp_syn_fins,event_type,flags,time_stamp,event_id,event_code)";
strCmd = "sqlldr xl/secreat@o11g control=" + strLoaderFile + " LOG=" + strLogFile;
System.IO.DirectoryInfo di;
try
{
System.Diagnostics.ProcessStartInfo cmdProcessInfo = new System.Diagnostics.ProcessStartInfo("cmd.exe");
di = new DirectoryInfo(strCSVPath);
strSQLLoader = "";
strSQLLoader += "LOAD DATA INFILE '" + strCSVPath.ToString().Trim() + "' " + append + " " + table;
StreamWriter writer = new StreamWriter(strLoaderFile);
writer.WriteLine(strSQLLoader);
writer.Flush();
writer.Close();
// Redirect both streams so we can write/read them.
cmdProcessInfo.RedirectStandardInput = true;
cmdProcessInfo.RedirectStandardOutput = true;
cmdProcessInfo.UseShellExecute = false;
cmdProcessInfo.LoadUserProfile = true;
//System.Diagnostics.Process.Start("CMD.exe", strCmdLine);
// Start the procses.
System.Diagnostics.Process pro = System.Diagnostics.Process.Start(cmdProcessInfo);
// Issue the dir command.
pro.StandardInput.WriteLine(strCmd);
// Exit the application.
pro.StandardInput.WriteLine("exit");
//Process[] processlist = Process.GetProcesses();
//foreach(Process pro in processlist){
Console.WriteLine("Process: {0} ID: {1}", pro.ProcessName, pro.Id);
Console.WriteLine(pro.StandardOutput.ReadLine());
//}
// Read all the output generated from it.
string strOutput;
strOutput = pro.StandardOutput.ReadToEnd();
pro.Dispose();
}
catch (Exception ex)
{
return;
}
finally
{
}
Thanks
Loading
Suthish NairPosted Mar 16, 2011, 1:55 PM
Vijay YadavPosted Mar 15, 2011, 10:25 AM
Thanks a lot!!!!:)
Guest UserPosted Mar 15, 2011, 9:23 AM
You can store this pathname as an AppSetting in the app.config file (so you can change it without having to recompile the app) and retrieve it using ConfigurationManager.AppSettings["my_app_pathname_setting"].
If the exe has its home directory stored in the registry you could also retrieve it from there.
Vijay YadavPosted Mar 15, 2011, 9:17 AM
Yes for files which are resides in our path. But what about the files which are not resides(that are resides in program files). Do you have any idea regarding this?
Guest UserPosted Mar 15, 2011, 8:51 AM
p.StartInfo.FileName = @"notepad.exe";
Vijay YadavPosted Mar 15, 2011, 3:36 AM
In the above code i.e. p.StartInfo.FileName = @"C:\Windows\notepad.exe"; here we have to provide the whole path of the exe in order to run the exe, Is there anywhere so that we should provide only exe name or something like this. If any idea please share it.
Guest UserPosted Mar 14, 2011, 8:49 AM
For example, this code will start Notepad from within a C# app. Note that it doesn't start cmd.exe:
Process p = new Process();
p.StartInfo.FileName = @"C:\Windows\notepad.exe";
p.StartInfo.Arguments = @"";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = false;
p.Start();