- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我整个上午都在处理这个问题,所以我来这里寻求帮助。阅读许多关于此的 SO 问题并尝试了所有解决方案但没有解决我的问题。
我刚开始使用 Process.Start(batchfile.bat);
它在某些计算机上有效,但在其他计算机上无效。在批处理文件不起作用的计算机上,命令提示符打开并显示
'ogr2ogr.exe' is not recognized as an internal or external command, operable program or batch file.
如果您打开命令提示符并运行它但不是通过双击批处理文件,则该命令工作正常。所以我开始尝试使用 ProcessStartInfo。
我正在选择一个文件并读取该文件。我从文件中读取的内容并不重要。
strFilePath = Path.GetDirectoryName(openFileDialog1.FileName);
此时strFilePath = O:\\03 Supervisors\\04_Production\\test
O:是一个映射驱动器。
我在该位置创建一个批处理文件并向其中写入一些命令。
File.CreateText(strFilePath + "\\" + "kml2shp.bat").Dispose();
我将要执行的命令写入我的批处理文件。
ogr2ogr.exe -f "ESRI Shapefile" "O:\03 Supervisors\04_Production\test\Final.shp" "O:\03 Supervisors\04_Production\test\_Map.kml"
PAUSE
我现在开始这个过程的代码是
try
{
ProcessStartInfo startInfo = new ProcessStartInfo();
if (File.Exists(strFilePath + "\\kml2shp.bat") == false)
{
MessageBox.Show("File is missing");
}
startInfo.FileName = strFilePath + "\\kml2shp.bat";
startInfo.LoadUserProfile = false;
startInfo.Domain = "mydomain";
startInfo.UserName = "myusername";
startInfo.Password = MakeSecureString("mypassword");
startInfo.UseShellExecute = false;
Process.Start(startInfo);
}
catch (Win32Exception w32E)
{
MessageBox.Show(w32E.ToString());
}
private static SecureString MakeSecureString(string text)
{
SecureString secure = new SecureString();
foreach (char c in text)
{
secure.AppendChar(c);
}
return secure;
}
如果我没有定义域、用户和密码,命令提示符会显示。
'ogr2ogr.exe' is not recognized as an internal or external command, operable program or batch file.
当我这样做时,它找不到文件。
那为什么我的File.Exists(strFilePath + "\\kml2shp.bat")
通过了,但是进程找不到文件呢?
我试过了
startInfo.WorkingDirectory = strFilePath + "\\";
startInfo.FileName = "kml2shp.bat";
似乎不喜欢进程中的路径是 O:\\03 Supervisors\\04_Production\\test
我假设路径中有空格,但我尝试了 20 种不同的方法来尝试用双引号将它括起来,但没有成功。有什么想法吗?
最佳答案
映射的驱动器不是全局的,它们特定于登录 session 。通过提供凭据,您要求 Process.Start
在单独的登录 session 中运行该程序,因此当进程尝试启动时,您的映射驱动器不再可用。因此出现“找不到路径”和“目录名称无效”错误。
听起来好像您无论如何都需要凭据,所以只需摆脱它们并解决原始问题:批处理器找不到ogr2ogr.exe
。最简单的解决方案可能是提供可执行文件的完整路径作为批处理文件的一部分。或者,如果批处理文件实际上不是必需的(从问题中不清楚您为什么首先使用批处理文件),您可以尝试使用 Process.Start
直接运行可执行文件。
关于c# - 系统找不到从 ProcessStartInfo 指定的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35138013/
ProcessStartInfo.EnvironmentVariables : A string dictionary that provides environment variables that
这是为什么 ProcessStartInfo myProcess = new ProcessStartInfo(path); myProcess.UserName = username; myProc
当我通过在 CMD 中键入以下内容手动向 Windows 添加服务时: “C:\Program Files (x86)\Windows Resource Kits\Tools\instsrv.exe”
根据 MSDN : 如果您没有使用 开始 启动进程的方法,开始信息 属性不反射(reflect)用于启动进程的参数。例如,如果您使用 获取进程 要获取计算机上运行的一系列进程,开始信息 每个人的属性(
当我尝试获取可执行文件的命令行参数时,我尝试检查 ProcessStartInfo Get-Process 返回的结构,但无论如何参数字段都是空的: PS C:\> ps notepad Handle
在我的 C# 应用程序中,我使用以下 ProcessStartInfo 调用 Process.Start(myPSI): ProcessStartInfo startInfoSigner = new
我创建了一个方法,它将以管理员身份执行 .exe 文件。 我想对两个不同的 .exe 文件使用相同的方法,但是 .exe 文件看起来彼此不同。因此,它们需要不同数量的参数。 方法如下: public
我正在将 C++ 代码移植到 C#,我在 C++ 代码中遇到了这个问题, SHELLEXECUTEINFO shell; memset(&shell, 0, sizeof(shell)); //the
我正在使用特殊的用户、域和密码启动一个进程。虽然我告诉 C# 隐藏它显示的控制台窗口。 这是我的代码: Process process = new Process(); process.StartIn
我正在使用 ProcessStartInfo 为文件打补丁,这样的文本文件(通过 cmd.exe): app.exe temp.txt patch.ips 我写了这段代码: ProcessStartI
这个问题在这里已经有了答案: Piping process output to new process (2 个答案) 关闭 5 年前。 在下面的 C# 代码中,我遇到了错误, ProcessSta
ProcessStartInfo.UseShellExecute 将如何影响我正在运行的进程? 我是否需要 UAC 的特殊权限才能使用 UseShellExecute? 它会在不同的用户上运行吗? 它
我整个上午都在处理这个问题,所以我来这里寻求帮助。阅读许多关于此的 SO 问题并尝试了所有解决方案但没有解决我的问题。 我刚开始使用 Process.Start(batchfile.bat); 它在某
我正在编写一个保持事件状态的服务来查看进程是否已启动并正在运行。我有几个同名的进程在不同的工作目录中运行。 因此,我想使用 WorkingDirectory属性作为唯一标识符。但是,当我查询所有这些属
我正在使用以下代码启动另一个带有参数的进程,这里我传递一个字符串路径作为参数,路径返回为 c:\documents and settings\\local settings: : string pat
但是它不起作用——这意味着 java 代码没有被执行。虽然批处理文件在 Windows 资源管理器中单击或在命令行中运行时运行良好.. 由于当批处理文件是单个 DOS 命令时这工作正常,我认为这在某种
如果你想启动另一个进程并等待(超时)完成你可以使用 the following (from MSDN) . //Set a time-out value. int timeOut=5000; //Ge
我想从 c# 代码运行一些 cmd 命令。我按照一些博客和教程得到了答案,但我有点困惑,即我应该如何传递多个参数? 我使用以下代码: System.Diagnostics.Process proces
我正在尝试从名为 teste.sh 的文件中运行以下命令 kpm restore k web 当我打开终端 cd 到正确的文件夹并执行“sh teste.sh”时,它们运行得很好,但是当我尝试在 mo
我想使用 shell 可执行文件以尊重要启动的应用程序的用户首选项,但我还需要知道该特定应用程序何时关闭。 Process editProcess = new Process(); ProcessSt
我是一名优秀的程序员,十分优秀!