相关疑难解决方法(0)

获取相对于当前工作目录的路径?

我正在编写一个控制台实用程序来对命令行上指定的文件进行一些处理,但是我遇到了一个我无法通过Google/Stack Overflow解决的问题.如果指定了完整路径(包括驱动器号),如何将该路径重新格式化为相对于当前工作目录?

必须有类似于VirtualPathUtility.MakeRelative函数的东西,但如果有,它就会让我失望.

c# file-io

74
推荐指数
4
解决办法
18万
查看次数

我如何直接在C#中执行批处理命令?

嗨我对c#和批处理文件有疑问.我想执行批处理命令并将输出保存在c#中的字符串中.但我只能执行该文件,但不能将此内容保存在字符串中,并在文本框中显示.

我的批处理文件:

@echo关闭

"C:\ lmxendutil.exe"-licstatxml -host serv005 -port 6200> C:\ Temp\HW_Lic_XML.xml notepad C:\ Temp\HW_Lic_XML.xml

这是我的c#代码:

private void btnShowLicstate_Click(object sender, EventArgs e)
{
     string command = "'C:\\lmxendutil.exe' -licstatxml -host lwserv005 -port 6200";

     txtOutput.Text = ExecuteCommand(command);
}

static string ExecuteCommand(string command)
{
     int exitCode;
     ProcessStartInfo processInfo;
     Process process;

     processInfo = new ProcessStartInfo("cmd.exe", "/c " + command);
     processInfo.CreateNoWindow = true;
     processInfo.UseShellExecute = false;
     // *** Redirect the output ***
     processInfo.RedirectStandardError = true;
     processInfo.RedirectStandardOutput = true;

     process = Process.Start(processInfo);
     process.WaitForExit();

     // *** Read the …
Run Code Online (Sandbox Code Playgroud)

c# xml binary batch-file bin

10
推荐指数
1
解决办法
1万
查看次数

将ProcessStartInfo.WorkingDirectory设置为UNC路径

我有一个我在VB.net中编写的实用程序,它作为计划任务运行.它在内部调用另一个可执行文件,它必须访问映射的驱动器.显然,当用户未登录时,即使将身份验证凭据提供给任务本身,Windows也会遇到计划任务访问映射驱动器的问题.好的.

为了解决这个问题,我刚刚通过了我的应用程序UNC路径.

process.StartInfo.FileName = 'name of executable'
process.StartInfo.WorkingDirectory = '\\unc path\'
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
process.StartInfo.Arguments = 'arguments to executable'
process.Start()
Run Code Online (Sandbox Code Playgroud)

这与我使用映射驱动器的实现相同,但是使用UNC路径时,该过程的行为不像UNC路径是工作目录.

将ProcessStartInfo.WorkingDirectory设置为UNC路径是否存在任何已知问题?如果没有,我做错了什么?

.net c# vb.net process.start

3
推荐指数
1
解决办法
9267
查看次数

标签 统计

c# ×3

.net ×1

batch-file ×1

bin ×1

binary ×1

file-io ×1

process.start ×1

vb.net ×1

xml ×1