Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command line escape sequence? 1

Status
Not open for further replies.

markharr

Vendor
May 21, 2001
87
AU
I want to be able to embed a carriage return or a line feed character (0x0d or 0x0a) in a parameter to a program on the command line in a regular .BAT or, if I have to, in VBScript. In a C program you can use an escape sequence (\n) to embed a carriage return in a string. How do I do this in a .BAT script? Assuming that it can be done at all.

I haven't done a lot with VBScript and the documentation is a little spotty. If someone has a simple example of executing a program with arguments with the WScript object I would appreciate the assistance. I'm not stupid but the VBScript documentation makes me feel that I am :).
 
Hello markharr,

For simple carriage return to accept the output of simple command like del or something, it is usually done by:
[tt]echo.|<thecommand>[/tt]

Else, if you need further help on making thing happen with vbs for good reason, feedback.

regards - tsuji
 
Hi there Tsuji, I'm afraid that I don't fully understand your answer. I can see in the documentation for echo that "echo." will produce a blank line in a script but I'm not sure how I could use that in the context of my problem.

The most likely reason is that I didn't explain myself well enough.

Here is an example of the sort of thing I would like to do:

C:\>mypgm "This is the text to log\nand this part should appear on the next line in the log"

Anyway, that gives you an idea of what I am trying to achieve though I suspect that what I want to do can't be done using CMD.EXE as the shell.
 
markharr,

In this case, it is entirely up to the mypgm to parse. If it recognizes \n as special character---as it should be because otherwise why the program?---, it acts accordingly. Otherwise, you are asking commandline to supply mypgm additional functionality.

- tsuji
 
Thanks. That is what I think also. I just needed a sanity check before I delivered the bad news.

Thanks again.
 
markharr,

If mypgm.exe (or whatever) take an argument with bare carriage return as a separator of "line", then it is very unfriendly with commandline for multiple line input. But, we are not here to criticize the foolishness of the design. It obviously has been running by effectively constraining users to single-line input all along in the past.

If it is so, I can conceive a .vbs solution to salvage this functionality.

Suppose the argument be multiple line figuratively like:
[tt]abc+carriage return+def ghi klm+carriage return+nop[/tt]

This is a solution using instead \n as separator. The user key in at command prompt
[tt]>cscript //nologo mypgm.vbs abc\ndef ghi klm\nnop[/tt]

with mypgm.vbs made like this.
Code:
const sig="\n"
const exefile="d:\test\mypgm.exe"
arg=""
for i=0 to wscript.arguments.count-1
	arg=arg & wscript.arguments(i)
next
arg=join(split(arg,sig),chr(13))
set wshshell=createobject("wscript.shell")
wshshell.run chr(34) & exfile & chr(34) & arg,,false
set wshshell=nothing
This will get it going. (Just to make sure it is the bare carriage return ascii code 0013 be the signature.) If this issue is important, give it a try.

- tsuji
 
I will pass the code snippet on. I know that the person with the problem has devised their own workaround as per the discussion we had on this already. I don't know if they will take this up.

Thank you again for your assistance. You really went the extra mile.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top