-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
49 lines (45 loc) · 1.72 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using IBM.Data.DB2.Core;
using System.IO;
using System.Threading;
using System.Diagnostics;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Welcome to Db2 .NET from OC 14");
//System.Diagnostics.Process.Start("CMD.exe", "yum install libxml2");
ExecuteCommand("yum install libxml2");
Console.WriteLine("executed install command");
Thread.Sleep(8000);
Console.WriteLine("Current directory is "+Directory.GetCurrentDirectory());
Console.WriteLine(" server : "+Environment.GetEnvironmentVariable("server"));
try
{
DB2Connection conn = new DB2Connection("DATABASE=SomeDb;server=yourserver:50000;UID=myuserid;PWD=testpwd;");
conn.Open();
Console.WriteLine("Connection Open and connected to server version "+conn.ServerVersion);
}
catch(Exception ex)
{
Console.WriteLine("Db2 Connection Error "+ex.Message);
}
Console.WriteLine("Complete");
}
static void ExecuteCommand(string command)
{
Process proc = new Process();
proc.StartInfo.FileName = "/bin/bash";
proc.StartInfo.Arguments = "-c \" " + command + " \"";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();
while (!proc.StandardOutput.EndOfStream)
{
Console.WriteLine(proc.StandardOutput.ReadLine());
}
}
}
}