C# Process.Start 参数被截断

发布于 2024-07-30 10:01:08 字数 206 浏览 2 评论 0原文

当传递很长的文件路径时,我的参数被截断。 我需要启动一个程序并通过命令参数传递所有内容 - 有时它只是截断命令。 它是在全局范围内进行的 - 因此这不仅是每个参数的问题,而且是整个参数的问题。

编辑: 正如 monkey_p 所说,问题可能是命令行长度的限制。 问题是:如何绕过它? (更改工作目录是行不通的,因为文件可能存在于不同的位置)。

I've got truncated parameters when passing very long file paths. I need to start a program and pass it everything via command params - sometimes it just truncates the command. It does it globally - so it's not only a problem for each parameter but for whole.

edit:
The problem is probably the limit on the command line length as monkey_p said. The questions is: How to bypass it? (changing working directory won't do becouse files can exist in different locations).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

栖竹 2024-08-06 10:01:08

我不确定您的问题是什么,但命令行有限制。 同样的限制对于 Process.Start(command,args) 也有效

在运行 Microsoft Windows 的计算机上
XP 或更高版本,最大长度
您可以在命令中使用的字符串
提示符为 8191 个字符。 在
运行 Microsoft Windows 的计算机
2000或Windows NT 4.0,最大
您可以使用的字符串的长度
在命令提示符下是 2047
字符。

I'm not sure what your question is, but there is a limitation on the commandline. This same limitation will be valid for Process.Start(command,args)

On computers running Microsoft Windows
XP or later, the maximum length of the
string that you can use at the command
prompt is 8191 characters. On
computers running Microsoft Windows
2000 or Windows NT 4.0, the maximum
length of the string that you can use
at the command prompt is 2047
characters.

千と千尋 2024-08-06 10:01:08

如何解决限制
解决该限制,使用一个或
更多以下方法(如
适合您的情况):

  • 修改
    需要长命令的程序
    行,以便他们使用一个文件
    包含参数信息,
    然后包含文件名
    在命令行中。

<块引用>
<块引用>

例如,不要使用
可执行文件.exe 参数1
参数2 ...参数N 命令行
在批处理文件中,将程序修改为
使用类似于的命令行
以下命令行,其中
ParameterFile 是一个文件,其中包含
所需参数(参数1
参数2 ...参数N):

<块引用>

ExecutableFile.exe c:\temp\ParameterFile.txt



  • 修改
    使用大环境的程序
    变量,以便环境
    变量包含小于任一
    2047 或 8191 个字符(如
    适用于您的操作系统)。

<块引用>
<块引用>

例如,如果 PATH 环境
变量包含多个
2047 或 8191 个字符(如
适合您的操作系统),
使用以下一项或多项
减少数量的方法
字符:


  • 使用较短的名称
    文件夹和文件。
  • 减少深度
    文件夹树。
  • 以更少的空间存储文件
    文件夹,以便减少文件夹数量
    PATH 环境中需要
    多变的。
  • 调查可能的情况
    您可以使用的方法来减少
    查找 .dll 的 PATH 依赖性
    文件。

这是来自 Microsoft 支持,所以对我没有任何帮助 - 似乎无法增加此限制并且无法以任何其他方式运行它...

我将尝试做的是: 记住每个文件的路径,将它们移动到某个 DIR,然后将 CurrentDirectory 设置为 DIR 运行程序,然后传入文件名,程序结束后将文件移回原来的位置 - 丑陋,丑陋,丑陋,我知道,但似乎没有其他方法......

How to work around the limitation To
work around the limitation, use one or
more of the following methods (as
appropriate to your situation):

  • Modify
    programs that require long command
    lines so that they use a file that
    contains the parameter information,
    and then include the name of the file
    in the command line.

For example, instead of using the
ExecutableFile.exe Parameter1
Parameter2 ...ParameterN command line
in a batch file, modify the program to
use a command line that is similar to
the following command line, where
ParameterFile is a file that contains
the required parameters (parameter1
parameter2 ...ParameterN):

ExecutableFile.exe c:\temp\ParameterFile.txt

  • Modify
    programs that use large environment
    variables so that the environment
    variables contain less than either
    2047 or 8191 characters (as
    appropriate to your operating system).

For example, if the PATH environment
variable contains more than either
2047 or 8191 characters (as
appropriate to your operating system),
use one or more of the following
methods to reduce the number of
characters:

  • Use shorter names for
    folders and files.
  • Reduce the depth of
    folder trees.
  • Store files in fewer
    folders so that fewer folders are
    required in the PATH environment
    variable.
  • Investigate possible
    methods that you can use to reduce the
    dependency of PATH for locating .dll
    files.

that is from Microsoft Support, so nothing helpful for me - it seems that this limit cannot be increased and there is no way to run it in any other way...

What I'll try to do is: Remember the path to each file, move them to some DIR and then run program with CurrentDirectory set to DIR and just pass in the file names and after program has ended move the files back to their place - ugly, ugly, ugly, I know, but it seems that there is no other way...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文