将参数传递给CMD,CMD返回“解析错误" [已解决] [英] Passing argument to CMD, CMD returns "parse error"[solved]

查看:97
本文介绍了将参数传递给CMD,CMD返回“解析错误" [已解决]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我希望有人能指出我正确的方向.我需要调用提升的cmd才能将文件夹从指定位置复制到另一个位置.遗憾的是,目标位置往往需要管理员权限才能修改.

无论何时运行,提升的cmd提示都会正确显示,但显示的只是"parse error"(解析错误).并等待下一个命令.如果我将CmdString字符串写到控制台并将其直接复制到cmd窗口中,它将完全按预期工作.

如果这是一个显而易见的答案,我感到非常抱歉.我已经搜索了几个小时,无法回避我做错的事情.

如果添加\ K开关,它将错误代码更改为'/K'不被识别为内部或外部命令,可操作程序或批处理文件."因此,我搜索到的唯一有些希望的结果不起作用.

Edit2:原来我确实是个白痴,/K开关必须位于copy.arguments值之前,而不是CmdString.如果其他人像我一样犯了一个愚蠢的错误,我将不予理会.

感谢您的阅读.很抱歉浪费您的时间.




解决方案


如果添加\ K开关,它将错误代码更改为'/K'不被识别为内部或外部命令,可操作程序或批处理文件".因此,我搜索出的唯一有些希望的结果不起作用.

Edit2:原来我确实是个白痴,/K开关必须位于copy.arguments值之前,而不是CmdString.如果其他人像我一样犯了一个愚蠢的错误,我将不予理会.

您好,

感谢您分享您的解决方案.我引用了您的解决方案,请将其标记为答案.它将帮助遇到类似问题的其他人.

最好的问候,
王丽


Hello,

I'm hoping someone can point me in the right direction. I need to call an elevated cmd to copy a folder from a specified location to another. Sadly the Target location tends to need admin rights to modify.

 
string CmdString = "xcopy /I /E"+ " " + "\"" + SourcePath +"\""+" "+"\""+ TargetPath +"\"";

ProcessStartInfo copy = new ProcessStartInfo("cmd.exe"); 
                copy.UseShellExecute = true;
                copy.Verb = "runas";
                copy.Arguments = "/K" + "\""+ CmdString + "\""; // /K Goes There Apparently.
                Process.Start(copy);

Whenever this is ran an elevated cmd prompt appears correctly but all it displays is "parse error" and waits for the next command. If I write my CmdString string to console and copy it directly into the cmd window it works exactly as expected.

I'm terribly sorry if this is an obvious answer. I have been searching for a couple of hours now and cannot wrap my head around what I have done wrong.

Edit: If I add the \K switch it changes the error code to "'/K' is not recognized as an internal or external command, operable program or batch file." So the only somewhat hopeful result my searches turned up doesn't work.

Edit2: Turns out I am indeed an idiot and the /K switch had to be prepended to the copy.arguments value rather than the CmdString. I'll leave this up incase anyone else makes a stupid mistake like I.

Thank you for reading.Sorry for wasting your time.




解决方案


Edit: If I add the \K switch it changes the error code to "'/K' is not recognized as an internal or external command, operable program or batch file." So the only somewhat hopeful result my searches turned up doesn't work.

Edit2: Turns out I am indeed an idiot and the /K switch had to be prepended to the copy.arguments value rather than the CmdString. I'll leave this up incase anyone else makes a stupid mistake like I.

Hi semi,

Thank you for sharing your solution. I quoted out your solution, please mark it as answer. It will help others who encounter similar issue.

Best Regards,
Li Wang


这篇关于将参数传递给CMD,CMD返回“解析错误" [已解决]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆