- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个程序,基本上剩下的就是通过 CMD.exe 调用命令。
我需要在我当前的工作目录中打开 CMD.exe(我知道我可以做 Porcess.Start(CMD.exe))
然后我需要让程序在 cmd.exe 中键入一个特定的字符串。留在我当前的工作目录中。我不能使用“UseShellExecute == false”,因为它会杀死 shell,我需要 shell 才能工作。
显然我需要更具体一些。所以,我试图写入 cmd.exe 的文本是 "clingo.exe\"Constants.txt\"\"Solver.txt\"\"Nodes.txt\">\"Solved.txt\""
。 clingo.exe 是一个答案集编译器,我在文件 Constants、Solver 和 Nodes 上使用它来获得通过管道传输到 Solved 的解决方案。所有这些文件都在一个目录中。
最佳答案
首先,我想知道为什么您认为 UseShellExecute=false
不适合您。有没有可能你只是没有正确使用它?
这是您的最佳选择。这适用于 99% 的应用:
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "clingo.exe",
Arguments = "\"Constants.txt\" \"Solver.txt\" \"Nodes.txt\"",
RedirectStandardOutput = true,
UseShellExecute = false
};
using(Process p = Process.Start(psi))
using(Stream s = File.Create("Solved.txt"))
{
p.StandardOutput.CopyTo(s);
p.WaitForExit();
}
这是一个罕见的应用程序选项,它不喜欢以标准方式传递的参数,但可以与 cmd.exe 一起使用:
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "cmd.exe",
RedirectStandardInput = true,
UseShellExecute = false // note this applies to cmd.exe specifically,
// NOT the processes that you start from cmd.exe
};
using(Process p = Process.Start(psi))
{
p.StandardInput.WriteLine("clingo \"Constants.txt\" \"Solver.txt\" \"Nodes.txt\" > \"Solved.txt\"");
p.StandardInput.WriteLine("exit");
p.WaitForExit();
}
您可能还需要重定向 StandardOutput 和 StandardError 才能正常工作——我忘记了!
关于c# - 命令行输入和 UseShellExecute == true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13639454/
我正在从我的 IIS Web 应用程序中启动一个小型控制台应用程序。代码是从应用程序池中使用这样的代码启动的, Process process = new Process(); ProcessStar
所以这是我的问题: 我已经启动了一个 .bin 文件,它只是一个 .exe,重命名为 .bin,具有管理员权限。 这是我的: PSI.FileName = "Client.bin"; PSI.Work
我有一个程序,基本上剩下的就是通过 CMD.exe 调用命令。 我需要在我当前的工作目录中打开 CMD.exe(我知道我可以做 Porcess.Start(CMD.exe)) 然后我需要让程序在 cm
ProcessStartInfo.UseShellExecute 将如何影响我正在运行的进程? 我是否需要 UAC 的特殊权限才能使用 UseShellExecute? 它会在不同的用户上运行吗? 它
我想启动一个具有提升权限但隐藏窗口的子进程(实际上是相同的控制台应用程序)。 我接下来要做的是: var info = new ProcessStartInfo(Assembly.GetEntryAs
在找出为什么某些应用程序可以运行我的应用程序(即 Minecraft 启动器)时遇到一些困难,它创建了一个 .bat 文件并使用 UseShellExecute 运行它。不确定是因为 UAC 垃圾还是
我想使用 shell 可执行文件以尊重要启动的应用程序的用户首选项,但我还需要知道该特定应用程序何时关闭。 Process editProcess = new Process(); ProcessSt
我正在开发一个使用 Process API 生成子进程的应用程序,并将 UseShellExecute 设置为 false。这个问题是我不想去寻找我正在生成的进程,因为它们在我的系统路径中可用。例如,
我有一个 MSBuild 任务执行(除其他外)对 xcopy 的调用。我发现,当我从一个批处理文件运行我的 MSBuild 任务时,对 xcopy 的调用正确执行,并且无法执行或产生任何输出,这些输出
// // Summary: // Gets or sets a value indicating whether to use the operating system shell //
如果我编写一个控制台应用程序,将另一个控制台应用程序作为一个新进程启动,并使用默认的“UseShellExecute”和“CreateNoWindow”值,结果是控制台应用程序窗口旁边会出现一个新的命
我需要从我的 UWP 应用程序调用批处理文件。方法似乎是 Process.Start(),但它说当我按照它输出的路径时,它甚至找不到文件,它确实存在。当使用 shellexecute = false
版本 dotnet 核心 SDK:2.1.403 docker :18.09.7 Linux 内核:5.0.0-27 Ubuntu:18.04.3 问题 我正在 docker 中运行一个 ASP.NE
我想从一个控制台运行多个 .Net Core 控制台应用程序。我有以下代码: var startInfo = new ProcessStartInfo("c:\path\to\file
我是一名优秀的程序员,十分优秀!