文件名、目录名或卷标语法不正确,c#

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/666983/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 12:32:00  来源:igfitidea点击:

The filename, directory name, or volume label syntax is incorrect, c#

c#.netbatch-file

提问by Anirudh Goel

i've written a console application deploy.exe which runs a batch script.

我编写了一个控制台应用程序 deploy.exe,它运行一个批处理脚本。

Process p1 = new Process();
p1.StartInfo.FileName = AppDomain.CurrentDomain.BaseDirectory + "installer.bat";
p1.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
p1.Start();
p1.WaitForExit();
p1.Close();

the installer.bat conatins the following command. \shared1\lists\list1.cmd

installer.bat 包含以下命令。\shared1\lists\list1.cmd

If i run the executable byitself it runs successfully.

如果我自己运行可执行文件,它会成功运行。

However i needed it to run in a windows installer project. So i made a setup and deployment project and added the deploy.exe successfully as custom action upon install.

但是我需要它在 Windows 安装程序项目中运行。所以我做了一个安装和部署项目,并在安装时成功添加了 deploy.exe 作为自定义操作。

It runs fine but when it starts to execute the command i get this error "The filename, directory name, or volume label syntax is incorrect". any help?

它运行良好,但是当它开始执行命令时,我收到此错误“文件名、目录名或卷标语法不正确”。有什么帮助吗?

采纳答案by Anirudh Goel

the error seems to be inside the script which was being executed. It contained environment variables %kind%, which were not acceptable by the installer for some reason. So it was working properly outside the installer and not properly when the installer was calling it.

错误似乎在正在执行的脚本中。它包含环境变量 %kind%,由于某种原因,安装程序无法接受这些变量。因此,它在安装程序之外正常工作,而在安装程序调用它时却无法正常工作。

回答by Samuel

Try printing out what the value of AppDomain.CurrentDomain.BaseDirectoryis. It may not be where installer.batis when you are installing it.

尝试打印出值AppDomain.CurrentDomain.BaseDirectory是什么。installer.bat当您安装它时,它可能不在何处。

Also, you tried adding the bat file to a custom action (if that is even possible)?

另外,您尝试将 bat 文件添加到自定义操作中(如果可能的话)?

And, would it possible to move what is in the bat to the exe?

而且,是否可以将蝙蝠中的内容移动到 exe 中?

回答by Reed Copsey

Is it a problem in your batch file?

你的批处理文件有问题吗?

Check this:

检查这个:

\\shared1\\lists\\list1.cmd

\\shared1\\lists\\list1.cmd

should probably be

应该是

\\shared1\lists\list1.cmd

\\shared1\lists\list1.cmd

Note the extra \ chars in your original command. That would cause the batch file to give that error.

注意原始命令中额外的 \ 字符。这将导致批处理文件给出该错误。