本文介绍了在 Process.Start() 中传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Process.Start("", "") 中将文件名作为参数传递.但是,我的参数似乎不起作用.

I want to pass the name of a file as an argument in Process.Start("", ""). However, my parameters don't seem to work.

这是我的代码:

Public Class Form1

Public Sub Button1_click(sender As Object, e As EventArgs) Handles btnClick.Click

    Dim myFile0 As String = "C:\Users\Desktop\1.pdf"
    Dim myFile2 As String = "C:\Users\Desktop\1s.pdf"

    Process.Start("cmd.exe", "/k pdftk" & myFile & "output" & myFile2 & "owner_pw password")

这不起作用,但如果我使用文件路径而不是 myFile0 或 myFile2,它可以正常工作.我需要能够使用这些变量.

That does not work, but if I use the file path instead of myFile0 or myFile2 it works fine.I need to be able to use the variables.

任何输入为什么它不起作用.我是 vb.net 的新手

Any inputs why it doesn`t work. I am new to vb.net

谢谢!

推荐答案

您忘记了文件名前后的空格.如果路径名包含空格,也强烈推荐双引号以避免麻烦.当您使用复合格式时,这总是更容易正确.修复:

You are forgetting the spaces before and after the file name. Double quotes are also strongly recommended to avoid trouble if the path name contains spaces. This is always easier to get right when you use composite formatting. Fix:

Dim args = String.Format("/k pdftk {0}{1}{0} output {0}{2}{0} owner_pw password", _
               """", myFile, MyFile2)
Process.Start("cmd.exe",  args)

这篇关于在 Process.Start() 中传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 23:11