![](/img/trans.png)
[英]I need to pass a command line script to a program from a windows service
[英]How to pass file to the program from the command line
我正在编写一个wpf应用程序,该程序应绘制文件中给定的点。
如何在命令行中将文件传递给C#程序? 例如类似
MyProgram.exe < file.txt
另外,如何在Visual Studio中进行调试? 我知道我可以设置命令行参数,并且可以使用
var args = System.Environment.GetCommandLineArgs().ToList();
您要做的就是以这种方式调用程序“ filedetails.exe myfile.txt”
范例:
C:\Users\FILEREADER>filedetails.exe myfile.txt
如何在命令行中将文件传递给C#程序? 例如>类似
MyProgram.exe <file.txt
您可以尝试使用此Console.OpenStandardInput()
我认为不可能将文件内容作为参数传递。 您当前正确地传递了文件内容:
MyProgram.exe < file.txt
您所需要做的就是阅读它,我放了一个小的cmd应用程序:
static void Main()
{
string line;
while ((line = Console.ReadLine()) != null)
{
Console.WriteLine(line);
}
}
在WPF应用程序中:
public MainWindow()
{
InitializeComponent();
var result = "";
string line;
while ((line = Console.ReadLine()) != null)
{
result += (line);
}
MessageBox.Show(result);
}
在此处查看有关命令行重定向的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.