Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Batch file with variables

FyeRooFyeRoo Member Posts: 5
I am trying to run a batch file from visual basic with variables. I am using the %1 and %2 for the variables in the script. I know that through the command line you can say cd c:program files, then when you are in the dir the batch file is in you say bathfile.bat variable1 variable2 variable3 etc. to tell it to run the batch file with those set variables.
I want to have the variables set in vb, then vb runs the batch file and puts the variables from the vb script into the run command for the batch file variables.

Tell me if that was confusing.

Comments

  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    : I am trying to run a batch file from visual basic with variables. I
    : am using the %1 and %2 for the variables in the script. I know that
    : through the command line you can say cd c:program files, then when
    : you are in the dir the batch file is in you say bathfile.bat
    : variable1 variable2 variable3 etc. to tell it to run the batch file
    : with those set variables.
    : I want to have the variables set in vb, then vb runs the batch file
    : and puts the variables from the vb script into the run command for
    : the batch file variables.
    :
    : Tell me if that was confusing.
    :
    :

    [code]
    Shell "C:Program Filesscript.bat " & Text1.Text & " " & Text2.Text
    [/code]
    Where Text1 and Text2 represent textboxes which contain the parameters.
    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • FyeRooFyeRoo Member Posts: 5
    : : I am trying to run a batch file from visual basic with variables. I
    : : am using the %1 and %2 for the variables in the script. I know that
    : : through the command line you can say cd c:program files, then when
    : : you are in the dir the batch file is in you say bathfile.bat
    : : variable1 variable2 variable3 etc. to tell it to run the batch file
    : : with those set variables.
    : : I want to have the variables set in vb, then vb runs the batch file
    : : and puts the variables from the vb script into the run command for
    : : the batch file variables.
    : :
    : : Tell me if that was confusing.
    : :
    : :
    :
    : [code]:
    : Shell "C:Program Filesscript.bat " & Text1.Text & " " & Text2.Text
    : [/code]:
    : Where Text1 and Text2 represent textboxes which contain the
    : parameters.
    : Best Regards,
    : Richard
    :
    : The way I see it... Well, it's all pretty blurry

    Okay thanks for the help, but now I present a new problem (like always)

    here is my shell command
    [code]
    Shell("C:Program FilesHLMCcompile.bat " & m_steamdir & " " & m_mapfile & " " & m_game & " " & m_steamid & " " & m_appnumber & " " & m_launch & " " & m_mapname)
    [/code]

    all of the variables have been set in the script before.
    When it gets to running the batch file I need the command line window to come up. Which it doesnt.

    I am not sure what is wrong.

    or if it is easier instead of running the batch file with variables have vb write the batch file and then execute it, please tell me.

  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    : Okay thanks for the help, but now I present a new problem (like
    : always)
    :

    Ahhh :) Why else would you bother programming - if not to solve problems

    : here is my shell command
    : [code]:
    : Shell("C:Program FilesHLMCcompile.bat " & m_steamdir & " " & m_mapfile & " " & m_game & " " & m_steamid & " " & m_appnumber & " " & m_launch & " " & m_mapname)
    : [/code]:

    Well the only thing that could go wrong with this code is if m_steamdir contains spaces... Enclose the variables that might have spaces in them by quotationmarks ("") in the string: Shell("compile.bat """ & m_steamdir & """")
    The """" looks terrible, but it's actually quite simple: "" = " character within a string. In a string, meaning it's surrounded by "". Thus for a string with just that character """".

    :
    : all of the variables have been set in the script before.
    : When it gets to running the batch file I need the command line
    : window to come up. Which it doesnt.
    :
    : I am not sure what is wrong.

    Nothing's wrong most likely. It's just that the cmd window closes automatically if the batch program doesn't have a pause in it. This is the same behaviour as when double-clicking it in Explorer.
    A way to solve this is to add a pause to the end of the batch file, or not call the batch file directly but to call cmd with parameters.
    Something like: Shell("cmd /K echo hello").

    :
    : or if it is easier instead of running the batch file with variables
    : have vb write the batch file and then execute it, please tell me.
    :

    Won't change anything... parameters are passed correctly. It'll just be way more error-prone with all the IO access etc.




    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • FyeRooFyeRoo Member Posts: 5
    : : Okay thanks for the help, but now I present a new problem (like
    : : always)
    : :
    :
    : Ahhh :) Why else would you bother programming - if not to solve
    : problems
    :
    : : here is my shell command
    : : [code]: :
    : : Shell("C:Program FilesHLMCcompile.bat " & m_steamdir & " " & m_mapfile & " " & m_game & " " & m_steamid & " " & m_appnumber & " " & m_launch & " " & m_mapname)
    : : [/code]: :
    :
    : Well the only thing that could go wrong with this code is if
    : m_steamdir contains spaces... Enclose the variables that might have
    : spaces in them by quotationmarks ("") in the string:
    : Shell("compile.bat """ & m_steamdir & """")
    : The """" looks terrible, but it's actually quite simple: "" = "
    : character within a string. In a string, meaning it's surrounded by
    : "". Thus for a string with just that character """".
    :
    : :
    : : all of the variables have been set in the script before.
    : : When it gets to running the batch file I need the command line
    : : window to come up. Which it doesnt.
    : :
    : : I am not sure what is wrong.
    :
    : Nothing's wrong most likely. It's just that the cmd window closes
    : automatically if the batch program doesn't have a pause in it. This
    : is the same behaviour as when double-clicking it in Explorer.
    : A way to solve this is to add a pause to the end of the batch file,
    : or not call the batch file directly but to call cmd with parameters.
    : Something like: Shell("cmd /K echo hello").
    :
    : :
    : : or if it is easier instead of running the batch file with variables
    : : have vb write the batch file and then execute it, please tell me.
    : :
    :
    : Won't change anything... parameters are passed correctly. It'll just
    : be way more error-prone with all the IO access etc.
    :
    :
    :
    :
    : Best Regards,
    : Richard
    :
    : The way I see it... Well, it's all pretty blurry

    Okay, thanks again. I have some pauses in the batch file so I dont think thats the problem, I will see what I can come up with tho.


Sign In or Register to comment.