Click here to Skip to main content
15,883,623 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone,

I am creating and calling a batch file from vb.net to run a java program(java command inside bat file).

The bat file is creating fine....but while running it some kind of weird sign is coming in front of the java command that is stopping system from recognizing java as any type of command.
I wonder what could be that thing!!!

here's code I used:

VB
Imports System
Imports System.IO

Module Module1

    Sub Main()

        Dim str, s1 As String

        s1 = "wednesday"
        str = "java pname """ & s1 & """"

        File.Create("D:\sa\MSG\sms_old\send.bat").Dispose()

        My.Computer.FileSystem.WriteAllText("D:\sa\MSG\sms_old\send.bat", str.Trim(), False)


        Dim processinfo As New ProcessStartInfo()
        processinfo.WorkingDirectory = "D:\sa\MSG\sms_old"
        processinfo.FileName = "send.bat"
        Process.Start(processinfo)

    End Sub

End Module


This should have produced this in command prompt:

D:\sa\MSG\sms_old>java pname "wednesday"

But it is producing something like this:

D:\sa\MSG\sms_old>java pname "wednesday"

Can anyone throw any light on it?

Thanks a lot!!!
Posted
Updated 22-Jul-14 21:14pm
v5
Comments
OriginalGriff 23-Jul-14 2:40am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Perhaps the code you use to run the batch file, and the batch file itself might help?
Use the "Improve question" widget to edit your question and provide better information.

I can't see anything too wrong - except the file creation code which is unnecessary and rather odd.
I'd do it like this:
VB
Dim str, s1 As String

s1 = "wednesday"
str = "java pname """ & s1 & """"
File.WriteAllText("D:\sa\MSG\sms_old\send.bat", str.Trim())

Dim processinfo As New ProcessStartInfo()
processinfo.WorkingDirectory = "D:\sa\MSG\sms_old"
processinfo.FileName = "send.bat"
Process.Start(processinfo)

Or even use "java" as the process and the remainder as the arguments to the ProcessInfo object - ignoring a BAT file completely.
 
Share this answer
 
Comments
planetz 23-Jul-14 6:19am    
it was a great help indeed...thank you so much!!
OriginalGriff 23-Jul-14 6:36am    
You're welcome!
Those weird characters are exactly 3 characters: they provide information on the encoding used in multi-byte encoded text files.
So it looks like ProcessStartInfo expects an ASCII (or other 8bit) encoded file.
System.IO.File.WriteAllText has overlaod which accepts an encoding parameter -
VB
System.IO.File.WriteAllText("D:\sa\MSG\sms_old\send.bat", str.Trim(), System.Text.Encoding.ASCII)

But of course, as OriginalGriff mentioned, you do not need the bat file, just use the command and parameters of the Process / ProcessStartInfo correctly
VB
System.Diagnostics.Process.Start("java", "pname """ & s1 & """)
 
Share this answer
 
Comments
planetz 23-Jul-14 6:18am    
thank u for explaining what it meant.....:-)

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