[英]Passing output of type command as a command line argument in C#
我想使用Win32命令type
打开JSON文件,然后通过命令行参数将其输出重定向到C#程序。
type Demo.json
给我
{
"Message" : "Hello World"
}
我想通过命令行参数将其传递给我的C#程序,如下所示
C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\csc.exe Demo.cs
Demo type Demo.json
但我得到的输出为: Demo.json
Demo.cs包括:
using System;
namespace Demo
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine(args[0]);
}
}
}
我想重定向type
命令的输出,以将其传递给命令行参数。
不要通过命令行参数传递文件的内容。 相反,将数据通过管道传输到stdin中,然后从stdin中读取程序:
class Program
{
static void Main(string[] args)
{
string contents = Console.In.ReadToEnd();
Console.WriteLine("Read from stdin: " + contents);
}
}
并运行它:
C:\Projects\ConsoleApp1\bin>type my-file.txt | ConsoleApp1.exe
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.