在 Process.Start 参数中传递引号 [英] Passing quotes in Process.Start arguments

查看:31
本文介绍了在 Process.Start 参数中传递引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 .NET 中,我正在运行这条线

In .NET i'm running this line

var p = Process.Start(@"cmd", @"/C mklink /H c:z c:za");

这一切正常,但我担心如果 mklink 的两个 args 之一有空间,这将无法正常工作.所以我在两个参数周围添加了".执行此行不再有效,当我写 "" 时,它仍然无效.

This works all fine however I'm worried that if one of the two args for mklink has a space that this wont work correctly. So I added "" around both parameters. Executing this line no longer worked and when I wrote "" instead it still didn't work.

我在执行cmd/C时如何写引号?

How do I write quotes when I am executing cmd /C?

推荐答案

string sourcePath = @"c:z";
string targetPath = @"c:za";

string arguments = string.Format(""{0}" "{1}"", sourcePath, targetPath);

var p = Process.Start("cmd", "/C mklink /H " + arguments);

工作示例:

string sourcePath = @"c:documents and settingsharvey robertMy DocumentsTest.txt";
string targetPath = @"c:	est";

string s = string.Format(""{0}" "{1}"", sourcePath, targetPath);
Process.Start("cmd", @"/c copy " + s);

已复制 1 个文件.

这篇关于在 Process.Start 参数中传递引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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