在选定的路径中运行脚本
我目前有这段代码:
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
I currently have this piece of code:
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
This copies two files in the current working directory (which will be the default install folder) to the selected path from the Fodler Dialog Browser. This works correctly.
Now what I want to do is too run "pdfmerge.py" into the selected folder path. I tried the below code but the script is still running in the current working directory.
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以设置进程的工作目录。
一个问题:您确保 dlgFolder.SelectedPath 正确吗?在不知道程序内部工作原理的情况下,似乎可以在
Button1
之前按BtnNow
,这意味着dlgFolder.SelectedPath
不会被设置用户。You can set the process's working directory.
One question: are you ensuring the
dlgFolder.SelectedPath
is correct? Without knowing the inner workings of your program, it appears possible to pressBtnNow
beforeButton1
, meaningdlgFolder.SelectedPath
won't have been set by the user.尝试使用带有 5 个参数的 Process.Start() 重载。
您可以为
userName
和password
传入null
,但如果您的目录不在您有权访问的标准目录范围内,您可能需要输入您的用户名和密码。我认为domain
将是工作目录。Try using the overload of Process.Start() that takes 5 arguments.
You may be able to pass in
null
foruserName
andpassword
, but if your directory is outside of the standard ones that you have permission for, you may need to put your username and password in.domain
would be the working directory, I think.