VS 2010 Run command line without command prompt-VBForums
Results 1 to 29 of 29

Thread: Run command line without command prompt

  1. #1

    Thread Starter
    Addicted Member HunterTTP's Avatar
    Join Date
    Jul 2012
    Posts
    146

    Question Run command line without command prompt

    Alright, so typically you would create a batch file for this and run it as so-

    Code:
    java -Xms1G -Xmx1G -jar Minecraft.exe
    I would like run this line of code when someone clicks a button in my program.

    I've tried-

    Code:
    Process.Start("C:\Users\" & Username & "\AppData\Roaming\HXL\Minecraft.exe", "Java -Xms1G -Xmx1G -jar")
    Which works, but then the game automatically tries to connect to a server named "-Xmx1G" which obviously isn't what I want.

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,242

    Re: Run command line without command prompt

    which obviously isn't what I want
    It may be obvious to you but .....

    If the batch file command is java first minecraft second would that not suggest that the process command should also be? Or is that too simplistic of me?
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    Addicted Member HunterTTP's Avatar
    Join Date
    Jul 2012
    Posts
    146

    Arrow Re: Run command line without command prompt

    Quote Originally Posted by dunfiddlin View Post
    It may be obvious to you but .....

    If the batch file command is java first minecraft second would that not suggest that the process command should also be? Or is that too simplistic of me?
    I should have been more specific. When you run the batch file, it starts the game with the specified amount of RAM. It doesn't make it connect to a server or anything of the sort.

    Also, if I wanted to run Java with the specifics (like the batch file) (as you suggest) what would that look like? How could I call Java without specifying a location?

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,242

    Re: Run command line without command prompt

    Well java should be on the Windows path so presumably ...

    Process.Start("java", "-Xms1G -Xmx1G -jar Minecraft.exe")

    ... should stand a chance.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5

    Thread Starter
    Addicted Member HunterTTP's Avatar
    Join Date
    Jul 2012
    Posts
    146

    Arrow Re: Run command line without command prompt

    Alright riddle me this; I need to specify where the Minecraft.exe is. So let's say-

    Process.Start("java", "-Xms1G -Xmx1G -jar C:\Minecraft.exe")

    But I think I need the "" around the C:\Minecraft.exe which VB.net isn't wanting to take..

  6. #6
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: Run command line without command prompt

    Quote Originally Posted by HunterTTP View Post
    Alright riddle me this; I need to specify where the Minecraft.exe is. So let's say-

    Process.Start("java", "-Xms1G -Xmx1G -jar C:\Minecraft.exe")

    But I think I need the "" around the C:\Minecraft.exe which VB.net isn't wanting to take..
    Wrong...

    You only need quotes around a filepath if there is spaces in it, because if there are spaces in a filepath, it will be recognized as not just the filepath as a single argument, but more than a single argument.

    Example: C:\folder name\file.exe - Would be recognized as the first being "C:\folder" and the second being "name\file.exe"

    And for VB.NET all you need to do to input a filepath is to double up on the quotes if you're typing the filepath in the IDE codeview.

    vbnet Code:
    1. Process.Start("java", "-Xms1G -Xmx1G -jar ""C:\Minecraft.exe""")
    <<<------------
    Improving Managed Code Performance | .NET Application Performance
    < Please if this helped you out. Any kind of thanks is gladly appreciated >


    .NET Programming (2012 - Present)
    ®Crestron - DMC-T Certified Programmer | Software Developer
    <<<------------

  7. #7

    Thread Starter
    Addicted Member HunterTTP's Avatar
    Join Date
    Jul 2012
    Posts
    146

    Question Re: Run command line without command prompt

    Alright, I appreciate the help!

    Whenever I click the button a command prompt comes up. It pauses for a moment, then displays "asdf"? After that it starts the program exactly as it should.

    1. I'm not sure what the asdf is about?

    2. The command prompt stays up until I close the game. How do I get this to either go away or be invisible?

  8. #8
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: Run command line without command prompt

    Look into ProcessStartInfo. Btw, there's no "asdf" in any code above, so you know that this is on your end, and something with the files involved and not the code.
    <<<------------
    Improving Managed Code Performance | .NET Application Performance
    < Please if this helped you out. Any kind of thanks is gladly appreciated >


    .NET Programming (2012 - Present)
    ®Crestron - DMC-T Certified Programmer | Software Developer
    <<<------------

  9. #9
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,141

    Re: Run command line without command prompt

    Looks like you don't need this info now but perhaps may help in the future.

    You could have just had your program call the bat file you originally mentioned.

  10. #10
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: Run command line without command prompt

    Personally, I say if you have a program compiled to call a batch file wouldn't it just be easier to click on the batch file itself and avoid the trouble of creating a program to do it for you? You could've also created a shortcut to that batch file, and then you'd have a shortcut where you can customize the icon to display as well for it all.

    The Process class otherwise, has everything you'd need for this type of task.
    <<<------------
    Improving Managed Code Performance | .NET Application Performance
    < Please if this helped you out. Any kind of thanks is gladly appreciated >


    .NET Programming (2012 - Present)
    ®Crestron - DMC-T Certified Programmer | Software Developer
    <<<------------

  11. #11

    Thread Starter
    Addicted Member HunterTTP's Avatar
    Join Date
    Jul 2012
    Posts
    146

    Question Re: Run command line without command prompt

    Alright well I managed to get the command prompt to go away by calling "javaw" instead of "java". I thought I was finished but now I've hit the last kink. Whenever I try to run any of the launchers over 1GB I get an "Unable to create java virtual machine" error. I'm reinstalling my java atm. I'm still puzzled on the asdf.. It is no where in my code; but it was the name of the batch file I used to use.

  12. #12

    Thread Starter
    Addicted Member HunterTTP's Avatar
    Join Date
    Jul 2012
    Posts
    146

    Re: Run command line without command prompt

    Well, I didn't make it just launch the batch file because I could not keep it from opening the command prompt.

  13. #13
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: Run command line without command prompt

    Quote Originally Posted by HunterTTP View Post
    Well, I didn't make it just launch the batch file because I could not keep it from opening the command prompt.
    Did you manage to see about the ProcessStartInfo like I mentioned? More specifically, the WindowStyle:

    vbnet Code:
    1. Dim procInfo As New ProcessStartInfo
    2. With procInfo
    3.     .FileName = "FileToExecute.exe"
    4.     .Arguments = "-arguments -go -here"
    5.     .WindowStyle = ProcessWindowStyle.Hidden
    6. End With
    7.  
    8. Process.Start(procInfo)
    <<<------------
    Improving Managed Code Performance | .NET Application Performance
    < Please if this helped you out. Any kind of thanks is gladly appreciated >


    .NET Programming (2012 - Present)
    ®Crestron - DMC-T Certified Programmer | Software Developer
    <<<------------

  14. #14

    Thread Starter
    Addicted Member HunterTTP's Avatar
    Join Date
    Jul 2012
    Posts
    146

    Re: Run command line without command prompt

    Alright, so -

    Code:
    Dim procInfo As New ProcessStartInfo
    With procInfo
        .FileName = "C:\asdf.bat"
        .Arguments = ""
        .WindowStyle = ProcessWindowStyle.Hidden
    End With
     
    Process.Start(procInfo)
    Like that?

  15. #15
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    21,474

    Re: Run command line without command prompt

    Quote Originally Posted by HunterTTP View Post
    Alright, so -

    Code:
    Dim procInfo As New ProcessStartInfo
    With procInfo
        .FileName = "C:\asdf.bat"
        .Arguments = ""
        .WindowStyle = ProcessWindowStyle.Hidden
    End With
     
    Process.Start(procInfo)
    Like that?
    probably. try it + see. there's also a createnowindow property

  16. #16
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: Run command line without command prompt

    Quote Originally Posted by HunterTTP View Post
    Alright, so -

    Code:
    Dim procInfo As New ProcessStartInfo
    With procInfo
        .FileName = "C:\asdf.bat"
        .Arguments = ""
        .WindowStyle = ProcessWindowStyle.Hidden
    End With
     
    Process.Start(procInfo)
    Like that?
    If you don't have any arguments you can leave that line out, by default it will assume you don't have arguments if you don't specify anything for that property.
    <<<------------
    Improving Managed Code Performance | .NET Application Performance
    < Please if this helped you out. Any kind of thanks is gladly appreciated >


    .NET Programming (2012 - Present)
    ®Crestron - DMC-T Certified Programmer | Software Developer
    <<<------------

  17. #17

    Thread Starter
    Addicted Member HunterTTP's Avatar
    Join Date
    Jul 2012
    Posts
    146

    Re: Run command line without command prompt

    That seemed to work fine. Everything goes exactly how it should, but the game does not start. I tried manually clicking the file and that works fine. I've pointed it like this..

    Code:
    'start batch
            Dim procInfo As New ProcessStartInfo
            With procInfo
                .FileName = "C:\Users\" & Username & "\AppData\Roaming\HXL\1GBatch.bat"
                .WindowStyle = ProcessWindowStyle.Hidden
            End With
    
            Process.Start(procInfo)
            Me.Close()
    I read somewhere that the batch has to be in the debug or release folder?

    The command prompt that will be hidden says-


    Code:
    C:\Users\Hunter\Dropbox\Public\Projects\HXL\XRAMLauncher\XRAMLauncher\bin\Debug>
    java -Xms1G -Xmx1G -jar Minecraft.exe
    Error: Unable to access jarfile Minecraft.exe
    
    C:\Users\Hunter\Dropbox\Public\Projects\HXL\XRAMLauncher\XRAMLauncher\bin\Debug>
    pause
    Press any key to continue . . .
    Last edited by HunterTTP; Nov 12th, 2012 at 08:27 PM.

  18. #18
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: Run command line without command prompt

    You can also use Environment variables for the special directory paths.

    %AppData% is a common Environment location for "...\AppData\Roaming"

    vbnet Code:
    1. Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\HXL\1GBatch.bat"

    Also make sure that that filepath is correct. UseShellExecute by default should be true, so I can't see Me.Close() interfering with this...
    <<<------------
    Improving Managed Code Performance | .NET Application Performance
    < Please if this helped you out. Any kind of thanks is gladly appreciated >


    .NET Programming (2012 - Present)
    ®Crestron - DMC-T Certified Programmer | Software Developer
    <<<------------

  19. #19

    Thread Starter
    Addicted Member HunterTTP's Avatar
    Join Date
    Jul 2012
    Posts
    146

    Unhappy Re: Run command line without command prompt

    I'm pretty lost on this one. I get the same outcome despite my execution. Here is the entire code for my first button-

    Code:
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            'kill Minecraft
            Dim pList() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcessesByName("javaw")
            For Each proc As System.Diagnostics.Process In pList
                proc.Kill()
            Next
    
            Label3.Invoke(Sub() Label3.Text = "Checking for files..")
    
            'batch check/download
            If My.Computer.FileSystem.FileExists("C:\Users\" & Username & "\AppData\Roaming\HXL\Minecraft.exe") Then
    
            Else
                Label3.Invoke(Sub() Label3.Text = "Downloading files..")
                My.Computer.Network.DownloadFile("https://dl.dropbox.com/u/37950074/Projects/HXL/Minecraft.exe", "C:\Users\" & Username & "\AppData\Roaming\HXL\Minecraft.exe")
            End If
    
            'mc check/download
            If My.Computer.FileSystem.FileExists("C:\Users\" & Username & "\AppData\Roaming\HXL\1GBatch.bat") Then
    
            Else
                Label3.Invoke(Sub() Label3.Text = "Downloading files..")
                My.Computer.Network.DownloadFile("https://dl.dropbox.com/u/37950074/Projects/HXL/Batch%20Files/1GBatch.bat", "C:\Users\" & Username & "\AppData\Roaming\HXL\1GBatch.bat")
            End If
    
            'start batch
            System.Diagnostics.Process.Start("C:\Users\" & Username & "\AppData\Roaming\HXL\1GBatch.bat")
            Me.Close()
        End Sub

  20. #20

    Thread Starter
    Addicted Member HunterTTP's Avatar
    Join Date
    Jul 2012
    Posts
    146

    Re: Run command line without command prompt

    Just built it and tried running it from my desktop. Seems to work fine from there?

  21. #21
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: Run command line without command prompt

    Why don't you Import the System.Diagnostics namespace at the top to make your life easier?

    (Also, is all of this multi-threaded?)

    Instead of having blank regions in your if statements for certain conditions, use the Not keyword. And also instead of My.Computer for File existence, I would use the System.IO namespace and the File methods available in there.

    What's not working with this though? Do you see a console pop up for the batch file using that current code?
    <<<------------
    Improving Managed Code Performance | .NET Application Performance
    < Please if this helped you out. Any kind of thanks is gladly appreciated >


    .NET Programming (2012 - Present)
    ®Crestron - DMC-T Certified Programmer | Software Developer
    <<<------------

  22. #22

    Thread Starter
    Addicted Member HunterTTP's Avatar
    Join Date
    Jul 2012
    Posts
    146

    Re: Run command line without command prompt

    I will look into it. I will continue to work on this tomorrow but I'm finding these walls I keep hitting to be stranger and stranger. If my program runs the 2GB batch, Java says it cannot allocate that much. But if I manually click the exact same batch, it loads up just fine.

  23. #23
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: Run command line without command prompt

    I'm no Java programmer, but this could be a Java auth issue then perhaps? (javaw.exe). If it is I can't help lol.. I am by no means a Java programmer, I never enjoyed Java even when I tried learning it. I much prefer C/C++ over Java, and I know the .NET framework and the languages that use it much more than what I know in Java.
    <<<------------
    Improving Managed Code Performance | .NET Application Performance
    < Please if this helped you out. Any kind of thanks is gladly appreciated >


    .NET Programming (2012 - Present)
    ®Crestron - DMC-T Certified Programmer | Software Developer
    <<<------------

  24. #24

    Thread Starter
    Addicted Member HunterTTP's Avatar
    Join Date
    Jul 2012
    Posts
    146

    Re: Run command line without command prompt

    I think it is because either my Program, or the Java it is starting, is running in a 32bit environment. Other sites have said that 32bit Java cannot have more than 1.5GB of memory in a virtual machine. I've tried adding -d64 to the arguments. But it says that this 32bit cannot run 64bit command or something similar to that.

  25. #25

    Thread Starter
    Addicted Member HunterTTP's Avatar
    Join Date
    Jul 2012
    Posts
    146

    Arrow Re: Run command line without command prompt

    Everything works fine if I wright the batch file like this-

    Code:
    "C:\Program Files\Java\jre7\bin\javaw.exe" -Xms2G -Xmx2G -jar Minecraft.exe
    But what if they have their java installed to a different location? u_u

  26. #26
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: Run command line without command prompt

    Then you probably need a 64 bit OS, and it reverts to the default 32 bit settings to save memory from being allocated for no reason in the heap, unless otherwise specified by this "-d64" command line option. Seems reasonable enough. The only way you can use that option is if you have a 64 bit OS though. I don't know much about Java though so don't take my word for it.

    You got it to work by changing your methods I see, did you not?

    Java by default should be in that location shouldn't it however? And to avoid strict hardcoded values, use the Enironment as I shown you in this post: http://www.vbforums.com/showthread.p...=1#post4278981

    Check for the existence of "C:\Program Files\Java\jre7\bin\javaw.exe", and if it doesn't exist, then prompt the user to input the filepath to javaw.exe.
    <<<------------
    Improving Managed Code Performance | .NET Application Performance
    < Please if this helped you out. Any kind of thanks is gladly appreciated >


    .NET Programming (2012 - Present)
    ®Crestron - DMC-T Certified Programmer | Software Developer
    <<<------------

  27. #27

    Thread Starter
    Addicted Member HunterTTP's Avatar
    Join Date
    Jul 2012
    Posts
    146

    Re: Run command line without command prompt

    hmm I know how to make it check for existence, but how do I prompt for them to input?

    And if they select it, it will have to edit the batch files. I will most likely have to go back to calling java and it's arguments in the program itself; but this time I'll have it pointed to the javaw.exe instead of calling java.

  28. #28
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: Run command line without command prompt

    but how do I prompt for them to input?
    This is the basics of programming Although it's also completely preference related. You choose how you want them to input the filepath.

    If your batch file has hardcoded values that would interfere, perhaps the batch script itself could be written a bit better as well. Make it use command line args itself to have dynamic values for instance?
    <<<------------
    Improving Managed Code Performance | .NET Application Performance
    < Please if this helped you out. Any kind of thanks is gladly appreciated >


    .NET Programming (2012 - Present)
    ®Crestron - DMC-T Certified Programmer | Software Developer
    <<<------------

  29. #29

    Thread Starter
    Addicted Member HunterTTP's Avatar
    Join Date
    Jul 2012
    Posts
    146

    Re: Run command line without command prompt

    Thanks for all the help. I was able to release the beta version of my program for now. Still have to let people choose the location of their Java and save that for re-use.

    http://www.minecraftforum.net/topic/...-need-testers/

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.