1

I have a batch file with the following 2 lines and change them into one line of code:

set arg=%1%
"C:\Program Files\TextPad 6\TextPad.exe" -u "D:\www\%arg:~14,-1%"

The context is that I'm using a webpage url-handler as described on http://msdn.microsoft.com/en-us/library/aa767914%28v=vs.85%29.aspx

Currently I'm doing it by setting the batch file as the url command, so the %1 is passed into that, then converted and then it runs the text-editor. But I'd rather do it all in the url command, so that I don't have to use the batch file any more.

Redzarf
  • 2,578
  • 4
  • 30
  • 40
  • FYI - The trailing percent in `set arg=%1%` is not needed, (though it is not doing any harm either). All that is needed is `set arg=%1` – dbenham Jul 26 '12 at 23:00

1 Answers1

4

After much trial & error, I found this works:

cmd.exe /v:on /c set arg=%1& start /D"C:\Program Files\TextPad 6" TextPad.exe "D:\www\!arg:~14,-1!"
wmz
  • 3,645
  • 1
  • 14
  • 22
  • +1, Great job. I should have known better that delayed expansion was required. I just didn't think it through properly. I'm deleting my faulty answer. – dbenham Jul 26 '12 at 23:37
  • Be careful - I think you may have an extra space in your arg value. You probably should remove the space before the `&` – dbenham Jul 26 '12 at 23:40
  • Trial and error seems to be the order of the day. I forgot to say that the param contains something like (100) at the end. So I changed your command to: `cmd.exe /v:on /c set arg=%1&set arg="D:\Staffey\www\adev\!arg:~13!"& start /D"C:\Program Files\TextPad 6" TextPad.exe !arg!` (a second `set arg` to do all the processing before calling the program.) That works now - thanks @wmz and @dbenham for your help! – Redzarf Jul 27 '12 at 14:48