How to run python tool Command includes cat and pipeline on Linux Server from dot net console App (C#)?

NALB 61 Reputation points
2023-02-27T15:09:52.5833333+00:00

Hello

I have asked on your platform earlier question of how to run python command tool from Visual Studio 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);

how ever trying to run command that include cat and pipelines not wotking .. I have tried executing the below code



My command line is (cat fileName.txt | toolName > text.txt)

i recived errors while executing the above code such as :

cat: '|': No such file or directory

cat: ToolName: No such file or directory

Can you please provide me with the right code and example of it ?

Thank you

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,201 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 56,846 Reputation points
    2023-02-27T16:46:32.0833333+00:00

    the pipe (|) and redirect (>) are shell command tokens (bash, etc). you can either create a shell script and execute or implement in you program.

    you implement pipe, by forking, redirect stdout to stdin, and then exec the new program. Windows does not really have this model, so process doesnt really have it. you will need to use streams

    process start cat redirecting output to a stream

    process start toolName redirect input to the the stream. from above.

    write the output of toolName output to the desired text file.

    note: while Ive written my own unix shell programs in the past, I used c. here is a simple explanation of how shells work:

    https://brennan.io/2015/01/16/write-a-shell-in-c/


1 additional answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 56,846 Reputation points
    2023-02-27T16:50:09.67+00:00

    (extra post to display)

    0 comments No comments