C#Process.Start参数被截断 [英] C# Process.Start parameters truncated

查看:304
本文介绍了C#Process.Start参数被截断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

传递非常长的文件路径时,我的参数被截断了。我需要启动一个程序,并通过命令参数将所有内容传递给它-有时它会截断命令。它在全局范围内执行-因此,这不仅是每个参数的问题,还是整个问题。

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.

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

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).

推荐答案


如何要解决限制,要
解决限制,请使用一种或
以下方法(因为
适合您的情况):

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


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



例如,不要在批处理文件中使用
ExecutableFile.exe Parameter1
Parameter2 ... ParameterN命令行
,而是使用类似于以下命令的命令行将程序修改为

的以下命令行,其中
ParameterFile是一个包含
必需参数的文件(parameter1
parameter2 ... ParameterN):

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






  • 修改使用大型环境
    变量的
    程序,以使环境
    变量包含的
    少于2047个字符或8191个字符(因为
    适合于您的



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

    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:





    • 为$ b $使用较短的名称b个文件夹和文件。

    • 减小深度
      文件夹树。

    • 将文件存储在更少的
      文件夹中,以便在PATH环境
      变量中需要更少的文件夹

    • 研究可能的
      方法,这些方法可用于减少PATH的
      依赖关系以查找.dll
      文件。

      • 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.
      • 来自 Microsoft支持,所以对我没有什么帮助-似乎无法提高此限制,并且无法以任何其他方式运行它...

        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...

        我将尝试做的是:记住每个文件的路径,将它们移动到某些DIR,然后在CurrentDirectory设置为DIR的情况下运行程序,只需传递文件名,然后在程序结束后移动文件恢复原状-丑陋,丑陋,丑陋,我知道,但是似乎没有其他方法...

        这篇关于C#Process.Start参数被截断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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