[英]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.