如何将带有空格的字符串作为程序的开始参数传递 [英] How to pass a string with spaces in it as start arguments for a program

查看:43
本文介绍了如何将带有空格的字符串作为程序的开始参数传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控制台项目,我想以一些参数argc 开始.我想从我的计算机向它传递一个路径,比如说 C:\\My Folder.如何传递空格?

I have a console project which I want to start with some parameters argc. I want to pass to it a path from my computer, let's say C:\\My Folder. How can I pass the spaces?

当我尝试阅读它时,我得到了类似 C:\\My 的东西.我读过我可以使用 " 传递它们.如果是这样,我如何将它们传递给字符串 ("C:\My Folder") 因为我是使用 Process.StartProcessStartInfo 命令启动这个程序?

When I try to read it I obtain something like C:\\My. I've read that I can pass them by using ". If so, how can I pass those to a string ("C:\My Folder") because I am start this program by using the Process.Start and ProcessStartInfo commands?

推荐答案

将参数用双引号括起来:

Wrap the argument in double quotes:

"c:\My Folder\some.exe" /a="this is an argument"

作为传递给 Process.Start 的字符串:

As a string passed to Process.Start:

process.StartInfo.Aguments = "\"this is an argument\"";

查看这篇文章&回答了解更多详情.

这篇关于如何将带有空格的字符串作为程序的开始参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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