ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

How to -connect- Windows Visual Basic Apps with Windows Batch files?

(1/4) > >>

OptimalDesigns:
For example, here is what is done between two batch files:
In demo.bat,
set tmp=ABC
...
call main.bat
---

In main.bat,
if not "%tmp%"="" echo got it, %%tmp%% = %tmp% ... it worked!!
---

Now without a 'demo.bat' file, how can I pass my %tmp% variable from Windows 7 to my main.bat?

Phil
PS tried following
' Create a script (within my VB app) to pass parameters to Windows Batch file
' nogo as of 7/13/2018 pbb, need help!

' oShell.run "cmd /V /C Set -ua tmp %" & "ABC", 3, True

f0dder:
Instead of using environment variables, can't you use commandline arguments instead?

4wd:
As f0dder said, just pass the variable to the command file.


--- Code: Text ---Process.Start("main.bat", "ABC")
The passed argument is referred to as %1 in the command file, eg.

main.bat

--- Code: Text ---@echo offif "%~1"  == "ABC" (echo We got something!) else echo We got nothing!
%~1 removes any leading/trailing quotes, (eg. "ABC" becomes ABC), in case the arg did include spaces, and then you include it in quotes to do the string comparison.

OptimalDesigns:
Not that simple ... many parameters are passed as is.  So, how to get a variable passed that bypasses the cmd line?  And, there are many ... many apps already developed that need this technique.

Thanks, Phil

f0dder:
Since your post mentions "oShell.run", I guess you're dealing with VBScript and not VB code?

In general, a parent process passes its environment down to a child process. At the operating system level, you can usually specify a new environment for the child process (e.g. to pass it data, like you want to). It doesn't seem like this is available in VBScript, though, so you're probably limited to the way you're currently trying to do it, prepending /set before the command you want to run.

A thing that springs to mind is you do "set -ua" - I don't know what the "u" parameter is supposed to do (not listed on my system with "set /?"), but more generally Windows uses forward-slash for arguments, not dash.

Here's a little cmd.exe session, which I hope will be instructive:
How to -connect- Windows Visual Basic Apps with Windows Batch files?

Also note that child environment is never propagated back to the parent process.

Navigation

[0] Message Index

[#] Next page

Go to full version