(extra post to force display)
How to run python tool Command on Linux Server from dot net console App (C#)?
Hello ,
I have a python command that runs python tool on Linux server but how I can run it from C# dotnet ?
Developer technologies ASP.NET ASP.NET Core
-
Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
2023-02-21T16:58:13.56+00:00
4 additional answers
Sort by: Most helpful
-
Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
2023-02-20T16:41:58.5466667+00:00 assuming the C# program is on the linux box, you use the process class to run a process
https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process?view=net-7.0
note: on linux Process.Start() will do a fork().
-
NALB 71 Reputation points
2023-02-21T15:19:43.8566667+00:00 Thank you for responding , but can you show me what my code should look like as I have tried to use the code that was provided inside the mentioned link but id did not work ?
This is my command that I use on my shell in Linux : amass enum -d test.com> ~/FolderXTest/file.txt
The problem my command not fille script it is tool ....
How can i translate and call it in vs on Linux Server ?
-
Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
2023-02-21T16:55:48.5666667+00:00 you need to capture the output and write to the file yourself.
// start process using var process = Process.Start(new ProcessStartInfo { UseShellExecute = false FileName = "amass", RedirectStandardOutput = true, ArgumentList = { "enum", "-d", "test.com" } }); // read std out var output = process.StandardOutput.ReadToEnd(); // wait for exit process.WaitForExit(); // write out out File.WriteAllText("~/FolderXTest/file.txt", output);
note: if the the output is large, then use streams. also you could create a shell script with the redirect and just execute the script. be sure to set the execute bit
using var process = Process.Start(new ProcessStartInfo { FileName = "myscript", }); process.WaitForExit();
-
NALB 71 Reputation points
2023-02-27T08:26:31.6533333+00:00 Hello ,
Thank you so much for responding this worked for me ... but how can i execute this kind of commands
(cat Test.txt | ToolName > Output.txt) as with previous code it did not work ...