最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - How to Convert this CMD line to System.Diagnostics.System ProcessStartInfo.Argument - Stack Overflow

programmeradmin0浏览0评论

I have this command line that someone helped me with:

type "\\NetworkDriveLocation\Folder\test.pdf"|find "pdf:Keywords"

I want to execute this in C# using System.Diagnostics.Process. When ran through cmd, it works as expected, but it doesn't seem to like the fact that I'm piping the output of the command into the find when running it through System.Diagnostics.Process. Here is the code so far:

Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
process.StartInfo = startInfo;
startInfo.WorkingDirectory = importFileDirectoryInfo.FullName;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
startInfo.Arguments = $"/c type \"{fileInfo.FullName}\" | find \"pdf:Keywords\"";
process.Start();
var output = string.Empty;
while(!process.HasExited)
{
    output += process.StandardOutput.ReadToEnd();
}

It basically exists immediately. If I remove: | find \"pdf:Keywords\", then it appends output. Copilot wasn't much help. I'm sure I'm just missing a syntax, but can't figure out what it is.

发布评论

评论列表(0)

  1. 暂无评论