run C code from C# -
is there way in can call c code c# code?
i have been reading lot of microsoft docs , have tried way time being:
process proc = new process(); proc.startinfo.workingdirectory = "path-to-c-code"; proc.startinfo.filename = "c-code-name"; proc.startinfo.useshellexecute = false; proc.startinfo.redirectstandardoutput = true; proc.start(); console.writeline(proc.standardoutput.readtoend()); proc.waitforexit();
but not working.
this string stays null no matter proc.startinfo.filename
this c code code process kill themself.
#include <stdlib.h> #include <time.h> #include <stdio.h> #include <signal.h> #include <sys/types.h> #include <unistd.h> int main(int argc, char *argv[], char *env[]) { int value1; int value2; srandom(time(null)); switch (random() % 7) { case 0: exit(random() % 10); break; case 1: value1 = value1 / (value2 - value2); break; case 2: kill(getpid(), sigkill); break; case 3: alarm(random() % 60); break; case 4: __asm__("sti"); break; case 5: value1 = *((int*) null); break; default: break; } return 0; }
thank in advance.
using system; using system.diagnostics; namespace rungnometerminal { class mainclass { public static void executecommand(string command) { process proc = new system.diagnostics.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 ()); } } public static void main (string[] args) { executecommand("gnome-terminal -x bash -ic 'cd $home; ls; bash'"); } } }
thanks j. piquard
Comments
Post a Comment