Share via

How to run python tool Command that include (Cat . pipeline )on Linux Server from dot net console App (C#)?

NALB 71 Reputation points
2023-02-27T15:03:30.67+00:00

Hello ,

I have asked before on How can I write python command in VS and you provided me with the below code

// 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);

Which worked for me however using Cat and pipelines for example something like that (cat Test.txt | ToolName > Output.txt).

Can you provide me with code how to do that ...

I have tried the below code however i keep getting errors as

cat: '|': No such file or directory

cat: toolName: No such file or directory

  using var process = Process.Start(new ProcessStartInfo
                {
                    UseShellExecute = false,
                    FileName = "cat",
                    RedirectStandardOutput = true,
                    ArgumentList = { "textFile.txt", "|", "toolName" }
                });
                // read std out
                var output = process.StandardOutput.ReadToEnd();
                // wait for exit
                process.WaitForExit();
                // write out out
                File.WriteAllText("/home/ladmin/Nada_SWE/outputs/IPs.txt", output);

Thank you

Developer technologies | ASP.NET | ASP.NET Core

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 83,666 Reputation points
    2026-02-12T21:48:48.91+00:00

    You have two approaches.

    • the first is to execute a script that implements the pipe.
    • the second is to implement the pipe in your c# code. You first execute the first program, and stream the output. You then execute the second program use the output stream from the first as the input stream to the second. You don’t need to wait for the first to complete before starting the second. You would then wait for the second process to exit.

    note: while the c# syntax is much more verbose than the Linux API, you implement pipes, by forking apps after setting stdin and stdout.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.