Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
VB
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()



Regards,
Aravind
Posted
Updated 13-Apr-18 1:30am

1 solution

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.
 
Share this answer
 
Comments
Aravindba 17-Apr-18 3:58am    
Hi, yes i changed code like this
Dim process As New System.Diagnostics.Process
process.StartInfo.FileName = "cmd.exe"
process.StartInfo.UseShellExecute = False
process.StartInfo.CreateNoWindow = False

process.StartInfo.RedirectStandardInput = True
process.StartInfo.RedirectStandardOutput = True

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


Application.DoEvents()



process.StandardInput.WriteLine("cd " & My.Settings.FLEX)
process.StandardInput.WriteLine("mutool draw -r 90 -B 1000 -o """ & viewPath & "\" & dynamicFLXname & ".pdf_%d.png"" """ & actualFilePath & """")

Application.DoEvents()

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


I am getting error in cmd prompt
error screenshot ---http://prntscr.com/j6axwa

what's the problem ? same code working in another windows app and win service also, when i create new win application with same code not working , why ?
OriginalGriff 17-Apr-18 4:12am    
Look at the error message - it couldn't be any clearer.
It can't find an application called "mutool", so either it isn't installed, isn't on the path, or isn't in the folder you are expecting it to be.

I can't fix that for you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900