G
gopal
Hi,
I have a console application whose purpose is to run the OSQL utility
from
my console application.
When my application is run, the OSQL utility is started and it has to
prompt for Database UserName & Password [Database Name & SQL files will
be provided as other options for this OSQL].
But i am having problems in getting from the prompt, Database -
UserName & Password
Once I get userName & Password, i already have the Database Server Name
& SQL file
Now i will install the SQL files on the particular database
Here is the code
static void Main(string[] args)
{
String[] sConnectionString;
try
{
ProcessStartInfo psi = new ProcessStartInfo("osql.exe","-Usa
-Psa");
psi.RedirectStandardOutput=false;
psi.RedirectStandardInput=false;
psi.RedirectStandardError=false;
psi.UseShellExecute=false;
psi.CreateNoWindow=true;
Process proc = Process.Start (psi);
ProcessOutputReader por = new ProcessOutputReader (proc);
por.Start();
proc.StandardInput.WriteLine (@"go");
Console.ReadLine();
proc.StandardInput.WriteLine ("Hello");
proc.StandardInput.WriteLine ("there");
}
catch (Exception e)
{
Console.WriteLine("{0}",e.ToString());
}
}
class ProcessOutputReader
{
Process proc;
public ProcessOutputReader (Process proc)
{
this.proc = proc;
}
public void Start()
{
new Thread (new
ThreadStart(ReadAll)).Start();
}
void ReadAll()
{
StreamReader reader =
proc.StandardOutput;
string line;
while ((line =
reader.ReadLine())!=null)
Console.WriteLine ("Process
output: {0}", line);
}
}
}
I have a console application whose purpose is to run the OSQL utility
from
my console application.
When my application is run, the OSQL utility is started and it has to
prompt for Database UserName & Password [Database Name & SQL files will
be provided as other options for this OSQL].
But i am having problems in getting from the prompt, Database -
UserName & Password
Once I get userName & Password, i already have the Database Server Name
& SQL file
Now i will install the SQL files on the particular database
Here is the code
static void Main(string[] args)
{
String[] sConnectionString;
try
{
ProcessStartInfo psi = new ProcessStartInfo("osql.exe","-Usa
-Psa");
psi.RedirectStandardOutput=false;
psi.RedirectStandardInput=false;
psi.RedirectStandardError=false;
psi.UseShellExecute=false;
psi.CreateNoWindow=true;
Process proc = Process.Start (psi);
ProcessOutputReader por = new ProcessOutputReader (proc);
por.Start();
proc.StandardInput.WriteLine (@"go");
Console.ReadLine();
proc.StandardInput.WriteLine ("Hello");
proc.StandardInput.WriteLine ("there");
}
catch (Exception e)
{
Console.WriteLine("{0}",e.ToString());
}
}
class ProcessOutputReader
{
Process proc;
public ProcessOutputReader (Process proc)
{
this.proc = proc;
}
public void Start()
{
new Thread (new
ThreadStart(ReadAll)).Start();
}
void ReadAll()
{
StreamReader reader =
proc.StandardOutput;
string line;
while ((line =
reader.ReadLine())!=null)
Console.WriteLine ("Process
output: {0}", line);
}
}
}