【发布时间】:2011-08-22 10:36:53
【问题描述】:
我目前有这段代码:
Sub Button1Click(sender As Object, e As EventArgs)
If dlgFolder.ShowDialog = Windows.Forms.DialogResult.OK Then
txtPath.Text = dlgFolder.SelectedPath
Try
Dim CopyFile As String = Path.Combine(Directory.GetCurrentDirectory, "pdftk.exe")
Dim CopyLocation As String = Path.Combine(dlgFolder.SelectedPath, "pdftk.exe")
Dim pyScript As String = Path.Combine(Directory.GetCurrentDirectory, "pdfmerge.py")
Dim pyLocation As String = Path.Combine(dlgFolder.SelectedPath, "pdfmerge.py")
System.IO.File.Copy(CopyFile, CopyLocation, True)
System.IO.File.Copy(pyScript, pyLocation, True)
Catch copyError As IOException
Console.WriteLine(copyError.Message)
End Try
End If
End Sub
这会将当前工作目录(将是默认安装文件夹)中的两个文件复制到从 Fodler 对话浏览器中选择的路径。这可以正常工作。
现在我想做的就是将“pdfmerge.py”运行到选定的文件夹路径中。我尝试了以下代码,但脚本仍在当前工作目录中运行。
Sub BtnNowClick(sender As Object, e As EventArgs)
Dim myProcess As Process
Dim processFile As String = Path.Combine(dlgFolder.SelectedPath, "pdfmerge.py")
myProcess.Start(processFile, dlgFolder.SelectedPath)
End Sub
【问题讨论】:
-
如果你在
Debug.Print dlgFolder.SelectedPathBtnNowClick中得到什么?另外,您确定Try块在Button1Click中完成吗? -
@jonsca 是的,try 块运行良好。问题是命令行参数。我想从 dlgFolder.SelectedPath 运行 pdfmerge.py 而不是当前工作目录
-
我明白你现在在说什么,进程开始了,尽管文件的完整路径正在本地调用它。嗯......必须有一种方法可以解决这个问题,但我可以看到系统是如何设置的。对不起,我之前误解了。
-
我认为这就是您所需要的,请查看 MSDN 页面以细化所需的参数(但 03-04 的旧消息来源说您需要做的就是将工作目录作为第三个传递论点,见this)。
标签: vb.net process cmd directory