简体   繁体   English

为什么此LINQPad Util.Cmd()调用失败?

[英]Why does this LINQPad Util.Cmd() call fail?

I'm trying to execute the Windows find command from LINQPad but it isn't working and I don't understand why. 我正在尝试从LINQPad执行Windows find命令,但是它不起作用,我不明白为什么。 This is my LINQPad script and I'm executing it in LINQPad as C# Statement(s). 这是我的LINQPad脚本,我正在LINQPad中以C#语句的形式执行它。

string find = @"find ""Processing request to "" ""Y:\Services\DynaMiX.Services.DatabaseMaintenance\*.log""";
find.Dump("find");
var results = Util.Cmd(find);
results.Dump();

The find.Dump("find") statement displays the following as expected. find.Dump("find")语句按预期显示以下内容。

find "Processing request to " "Y:\Services\SteveC.Services.DatabaseMaintenance\*.log"

When I copy that and paste it in a CMD window it executes the find as it should but when running the script in LINQPad it throws CommandExecutionException with the ErrorText FIND: Parameter format not correct . 当我将其复制并粘贴到CMD窗口中时,它将按原样执行查找,但是在LINQPad中运行脚本时,它将抛出CommandExecutionException以及ErrorText FIND:参数格式不正确

Can anyone shed any light on why this might happen? 谁能阐明为什么会发生这种情况?

Turns out to be an incorrect use of Util.Cmd on my part. 原来是我对Util.Cmd的不正确使用。 Instead of Util.Cmd(string commandText) I needed to use the Util.Cmd(string commandText, string args) overload. 我需要使用Util.Cmd(string commandText, string args)重载Util.Cmd(string commandText, string args)而不是Util.Cmd(string commandText) The following statement works. 以下语句起作用。

var results = Util.Cmd("find", @"""Processing request to "" ""Y:\Services\SteveC.Services.DatabaseMaintenance\*.log""");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM