Passing parameters in Shell command in VB 6 - vb6

I have 2 EXEs in VB 6. EXE 1 calls the other EXE2 through shell command
EXE1 :
Shell(PathName\EXE2,0)
Now all I want is to pass a string type variable to EXE2 which I wish to receive in that EXE2.
How can I achieve the same?
Thanks in advance

Simply append the string (possibly quoted) to the end of the filename:
Shell("""PathName.exe"" wibble", vbNormalFocus)
or:
Shell("""PathName.exe"" ""wibble"" ""wibble 2""", vbNormalFocus)
This value can then be read in the other application using the Command$() function which will include everything after the path name and space, including any quotes around the parameters (e.g. "wibble" "wibble 2").

Related

Link Assembling

So I tried to make a script where a specific program opens the link but it only opens a part of it, can someone please help?
elseif result == "GOTO_ULTRABOOK_LEVEL" then
local randomLevelDigit = _G.math.random(1, 14)
local lvlURL = "https://ab-in-adventure.appspot.com/embed?levelId=1-" .. randomLevelDigit .. "&levelName=level-" .. randomLevelDigit
local basilisk = "Basilisk-Portable.exe"
--openURL()
_G.os.execute(basilisk, lvlURL)
_G.os.execute(basilisk, lvlURL) won't work. The second argument lvlURL is ignored as os.execute only takes one string argument.
In the manual you'll find os.execute ([command]). This tells you that os.execute has a single optional parameter. Single because there is nothing else in the parentheses. Optional because it is in square brackets.
So in order to make it work simply provide the complete shell command to os.execute as a single string.
As you're already using the string concatenation operator in your snippet you'll know what to do.

How to pass double quoted arguments into vbscript?

I am a new bee for vbScript. I have a script that I am calling with an arguments which contains double quote. Following is the call
.vbs "a" 2 where variable a is JO"N
My VbScript:
If WScript.Arguments.Count > 0 Then
MsgBox "NAME:" + WScript.Arguments.Item(0)
MsgBox "NAME:" + WScript.Arguments.Item(1)
Else
MsgBox "Please pass a parameter to this script"
End if
*Note this works when a = JON but does not work when a= JO"N. I tried putting escape characters" (Example: "WScript.Arguments.Item(0)") but it does not work.
You can't.
At least, as the WScript argument parser handles and removes all quotes from the values in Arguments collection, you can not use the default argument handling for this task.
note: And we are leaving out of the problem if the final command you are running when calling your script (you have not included how/from where you make the call) will or not have problems because the additional quote interferes argument quoting rules.
You need to use some workaround to get the double quote to reach the script. Some approachs could be:
Replace the quote and any other problematic character (use some kind of escape sequence) before calling the script and revert the process inside your script.
Save the value you want to pass into an environment variable (how to make it depends on how you are callign the script) and then retrieve the value from your script (ex. here).
Use WMI to retrieve the full command line used to start the script, including all the quotes (ex. here) and write your own argument parser routine.
From my point of view, I would use the second option.
This will work: Chr(34) & Wscript.Arguments.Item(0) & Chr(34). Here Chr(34) function returns a double quote using its ASCII code 34.

Using Write command to create new syntax - problem with unwanted spaces

I am trying to run a command on a list of variables stored as values in a different file. To do that I am creating a new syntax based on the variable names, like this:
WRITE OUT="\Selection.sps"
/"VARIABLE ATTRIBUTE VARIABLES = Final_",Var1," ATTRIBUTE=selectVars('yes')." .
EXECUTE.
The Problem is between Final and Var1, I am getting 11 spaces. The file in which I want to use this macro has variable names as Final_Var1 (So in the new file, Final is added to each variable's Name). How can I remove the space so that the new variable can be referred to properly? Should I create a new file or COMPUTE and CONCAT commands?
The write command is limited like that - you can't avoid the spaces or use trim. For commands like the one you're working on there is no way to build the command within the write command - you have to build the text in advance and then put it in the write command, so -
strimg mycmd(a100).
compute mycmd=concat("VARIABLE ATTRIBUTE VARIABLES = Final_",
ltrim(string(Var1,f4)),
" ATTRIBUTE=selectVars('yes').").
WRITE OUT="\Selection.sps" /mycmd .
exe.
Note that this is not the only way to work on variable lists - you can use Python code within the syntax to build your variable lists more efficiently.
I have found a temporary solution, in order to remove the spaces from the variables, I am creating a new variable using:
*Add a variable to use in .sps file.
NUMERIC A(F4).
COMPUTE A = Var1.
ALTER TYPE A (A25).
STRING CMD (A100).
COMPUTE CMD = CONCAT("VARIABLE ATTRIBUTE VARIABLES = Final_", LTRIM (A) , ATTRIBUTE=selectVars('yes').").
EXECUTE.
WRITE OUT="File location\Selection.sps" /CMD.
EXECUTE.
and now a macro can be created using Selection.sps.
If a simpler way exists, please let me know!

How to pass a variable with multiple spaces to a batch script?

I'd like to pass a variable with multiple spaces to a batch script, but it removes multiple spaces and replaces it with one.
C:\user\bat\myscript.bat var1 var2 "'var3'" "'some text followed by double blank__some more text'"
__ are to show the two blanks (' ', spaces, not underscore)
I already tried with %~4, %4 etc. but it always removes the double blanks.
br,
Manuel
The bat script is called from a Java application which gets the whole call string from a database.
Script call:
C:\user\bat\eqkvard.bat C:\user\reports\eqkvard.rdf C:\user\output\kontrollvarianten\myoutput.pdf "''"
"'00.101 D-Bereiche LKZ + OKZ(blank)(blank)L52 Gbd.151 -Mediafill'"
The site does not show both blanks.
The syntax for the quotes is the following: (")(')text(")
Script itself:
START "myprogram" /MIN rwrun report=%1 userid=user/pw#myDB desformat=pdf destype=file desname=%2 p_1=%3 p_2=%4
The script calls the Oracle reports runtime with the parameters.
Hope this can help.
Thank you for your answers.
The problem was in the Java call of Runtime exec, which removes double blanks from the String. It may be possible with an String array, but this is not suitable for my case.
If you are having the same problem with the Java exec command, the following post may help.
Runtime Exec with multiple spaces

Go generate escape characters

I have a go generate directive which looks like this:
//go:generate myprog -someName thisname -data 'Request: Typ "." callMe, Rsp: MyTyp "." close'
The issue is that the program receives only value of -someName flag ("thisname"). I assume the -data flag is discarded for some reasons. Any idea why? It's working if I execute the program directly from command line so I guess it's a go specific issue.
From the design document of go generate https://docs.google.com/document/d/1V03LUfjSADDooDMhe-_K59EgpTEm3V8uvQRuNMAEnjg/edit:
The arguments are space-separated tokens (or double-quoted strings) passed to the generator as individual arguments when it is run.
So if you want to pass an argument containing space you will have to double quote them. You used single quotes which works in your shell but not with go generate

Resources