Vbscript MsgBox newline from batch argument

0

test.vbs:

wscript.quit MsgBox ("Hello"&vbNewLine&"World",0)

works.

prova.bat:

WScript //Nologo Message.vbs "Hello"&vbNewLine&"World" 0

Message.vbs:

wscript.quit MsgBox (wscript.arguments(0),wscript.arguments(1))

not works (Why?).

prova.bat (without newline)

WScript //Nologo Message.vbs "Hello World" 0

works.

Riccardo La Marca

Posted 2017-08-24T18:59:54.047

Reputation: 163

The command line being passed end up being: WScript //Nologo Message.vbs "Hello" due to the " This can be seen in Process Explorer - http://imgur.com/a/7I7MA

– HelpingHand – 2017-08-24T19:16:47.057

1Great! You were able to post. But what exactly is your question? – LPChip – 2017-08-24T19:37:19.300

What do you want to happen? Do you want a space in the first argument to be replaced with a newline? – davidmneedham – 2017-08-24T19:50:20.030

1Any ampersands (&) must be escaped with a caret (^&). I also suggest using Replace(wscript.arguments(0), "\n", vbNewLine) in your VBScript and changing your .bat file to something like WScript //Nologo Message.vbs "Hello\nWorld" 0 – davidmneedham – 2017-08-24T20:12:24.893

Answers

1

In a VBS script, the ampersand & means "concatenate" (join) and vbNewLine is a defined constant.

In a batch file, the ampersand means "execute this after the previous command is finished," and vbNewLine is undefined.

Context is everything here, and you need to figure out what it is that you are passing, and what the operators and variables in each context mean. One of the comments above offers a viable way to take the input from one context and convert it to the other context.

Yorik

Posted 2017-08-24T18:59:54.047

Reputation: 2 956

0

Dim Messaggio
Messaggio = Replace(wscript.arguments(0),"\n",vbNewLine)
wscript.quit MsgBox(Messaggio,wscript.arguments(1))

Is perfect for Universal Message Box with batch! ;-)
With return value in %errorlevel% in case of choice.
Thanks at all!

Riccardo La Marca

Posted 2017-08-24T18:59:54.047

Reputation: 163