如何在VB.NET中使用参数运行cmd [英] How to run cmd with arguments in VB.NET

查看:295
本文介绍了如何在VB.NET中使用参数运行cmd的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我尝试使用pdfjson.exe从pdf生成js文件,当我在cmd提示符下运行(手动)它可以工作,如果我使用vb.net运行它,而不是生成js文件。但是它命中了所有进程代码,js文件只是没有生成。



有没有其他方法可以从vb.code运行cmd?



我尝试过:



这是我在vb.net中的代码

Hi I try to generate js file from pdf using pdfjson.exe, when i run in cmd prompt (manually) it works, if i run that using vb.net, not generating js file.But it hit all process code,js file only not generating.

Is any other way to run cmd from vb.code?

What I have tried:

This is my code in vb.net

Dim process As New System.Diagnostics.Process
        process.StartInfo.FileName = "cmd.exe"
        process.StartInfo.UseShellExecute = False
        process.StartInfo.CreateNoWindow = True
        process.StartInfo.RedirectStandardInput = True
        process.StartInfo.RedirectStandardOutput = True

        process.Start()
        Dim actualFilePath As String =Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase).Substring(6) & "\sample\a.pdf"
        Dim viewPath As String = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase).Substring(6) & "\sample"
        Dim dynamicFLXname As String = "a"

        process.StandardInput.WriteLine("cd " & My.Settings.FLEX)
        process.StandardInput.WriteLine("pdf2json.exe """ & actualFilePath & """ -enc UTF-8 -hidden -compress """ & viewPath & "\" & dynamicFLXname & ".js""")


        process.StandardInput.WriteLine("exit")
        Dim input As String = process.StandardOutput.ReadToEnd
        process.Close()







问候,

Aravind




Regards,
Aravind

推荐答案

首先使用调试器,然后查看要发送到系统的字符串,包括您在CD命令中添加的路径。

然后,删除exit和process.Close命令,更改StartInfo以创建一个窗口,并通过查看它的响应来查看命令对输入的确切操作。



我?我将EXE文件设置为启动过程,并将剩余数据作为参数传递给该命令 - 并设置ProcessStartInfo对象的WorkingDirectory属性,而不是根据输入进行操作。
Start by using the debugger, and look at the string you are sending to the system, including the path that you tack onto the CD command.
Then, remove the "exit" and process.Close commands, change your StartInfo to create a window, and look at exactly what the command is doing with your inputs by reviewing it's responses.

Me? I'd set the EXE file as the process to start, and pass the remaining data as the parameters to that command - and set the WorkingDirectory property of the ProcessStartInfo object instead of faffing with the input at all.


这篇关于如何在VB.NET中使用参数运行cmd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆