Last active
July 25, 2023 17:47
-
-
Save dixsonhuie/b91c6f662aaf3fe2bdd5539becaacb60 to your computer and use it in GitHub Desktop.
dotnet examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// c# start process example | |
public class StartProcess | |
{ | |
public void Start(string command, string args, string workingDir) | |
{ | |
try | |
{ | |
Process proc = new Process(); | |
// StartInfo | |
proc.StartInfo.FileName = command; | |
proc.StartInfo.Arguments = args; | |
proc.StartInfo.WorkingDirectory = workingDir; | |
proc.StartInfo.CreateNoWindow = true; | |
proc.StartInfo.UseShellExecute = false; | |
proc.StartInfo.RedirectStandardOutput = true; | |
proc.StartInfo.RedirectStandardError = true; | |
Console.WriteLine("About to start {0} {1} in directory {2}", command, args, workingDir); | |
Boolean? started = proc.Start(); | |
Console.WriteLine("process id is: {0}", proc.Id); | |
if (started == null) | |
{ | |
string errMsg = String.Format("Error while running {0} {1} in directory {2}", command, args, workingDir); | |
throw new InvalidOperationException(errMsg); | |
} | |
// Read the stdout, stderr | |
string output = proc.StandardOutput.ReadToEnd(); | |
Console.WriteLine(output); | |
string err = proc.StandardError.ReadToEnd(); | |
Console.WriteLine("Errors were encountered while running process: {0}", err); | |
// make process Start a blocking call | |
int timeoutInMillis = (5 * 60 * 1000); | |
bool waitForExitStatus = proc.WaitForExit(timeoutInMillis); | |
Console.WriteLine("process exited with code: {0}", proc.ExitCode); | |
// TODO - check status and implement kill? | |
proc.Close(); | |
} | |
catch (Exception e) | |
{ | |
Console.Write(e.Message); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get datbase tablename from NHibernate from Type of class - entryType below | |
var classMetaData = SessionFactory.GetClassMetadata(entryType) as NHibernate.Persister.Entity.AbstractEntityPersister; | |
string tableName = classMetaData.TableName; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment