Codingbatch files - pipe to variable?

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  Peter (BOUGHTONP)  
 To:  ALL
35458.1 
Windows batch files. (yay)

I want a variable which contains all command line arguments except the first two, preferably prefixed with a hyphen.

I can achieve that like this:
code:
ECHO %* | sed -e 's/%1 %2/ -/'

(I've got a sed.exe for Windows on my path)

However, I can't figure out how to put that into a variable which I can make use of in further commands?

The SET command doesn't allow piping, and only evaluates numeric expressions.

Any ideas?
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  ALL
35458.2 
Hmmm, so the SHIFT command allows you to remove the first command and shift the others all left one.

However, it looks like it affects the numbered %0 %1 %2 variables, and doesn't appear to %*, so this doesn't work:
code:
SHIFT
SHIFT
SET myvar=%*


:(
0/0
 Reply   Quote More 

 From:  Ally  
 To:  Peter (BOUGHTONP)     
35458.3 In reply to 35458.1 
I will repeat Rendle's advice to you in the past- learn C#, you'll have a console application up and running in two minutes.
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Ally     
35458.4 In reply to 35458.3 
I don't have .NET installed on this machine, and don't want to have to always compile the script as I adapt it.

If I can't do this with BAT then I'll switch to WPF, which will let me use JavaScript.
0/0
 Reply   Quote More 

 From:  THERE IS NO GOD BUT (RENDLE)  
 To:  Peter (BOUGHTONP)     
35458.5 In reply to 35458.4 
Aren't you using PowerShell?

0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  THERE IS NO GOD BUT (RENDLE)     
35458.6 In reply to 35458.5 
Ah, one of our Network Services guys was talking about that a while ago ...and then he ran away to the Netherlands before telling me about it more. :(

Do you have any good overview tutorial links to hand?

(And is it worth getting the 2.0 CTP, or is 1.0 good enough?)
1.0 has stupid Windows Genuine Advantage crap. 2.0 CTP doesn't, so I've gone with that.
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  ALL
35458.7 
Why does it take THREE SECONDS for PowerShell to actually start? :|
0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  Peter (BOUGHTONP)     
35458.8 In reply to 35458.7 
Because it's quick :|

0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  ANT_THOMAS     
35458.9 In reply to 35458.8 
Three seconds for a shell is not quick.

I found some pages related to running an ngen command, and it has cut the time to around 0.8 seconds, but that's still far too slow.

CMD and BAT files are almost instant.


Update...
I just created the following:
code:
ECHO %TIME% before PS
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe weee.ps1
ECHO %TIME% after PS
 
ECHO %TIME% before BAT
CALL weee.bat
ECHO %TIME% after BAT
 
ECHO %TIME% before BAT2
START /WAIT weee2.bat
ECHO %TIME% after BAT2


(the weee.ps1 and weee.bat both contain ECHO "Weee" the weee2.bat also contains an EXIT command.)

PS takes between 75ms and 85ms to run every time.

First BAT runs with no time difference at all (doesn't wait?).

Second BAT runs on average in 6ms (varies from 4ms to 7ms)
0/0
 Reply   Quote More 

 From:  THERE IS NO GOD BUT (RENDLE)  
 To:  Peter (BOUGHTONP)     
35458.10 In reply to 35458.7 
Because it's an insanely powerful object-oriented scripting environment, not an OS command line.

0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  THERE IS NO GOD BUT (RENDLE)     
35458.11 In reply to 35458.10 
If I wanted an insanely powerful object-oriented scripting environment, I'd use C#Java.
0/0
 Reply   Quote More 

 From:  THERE IS NO GOD BUT (RENDLE)  
 To:  Peter (BOUGHTONP)     
35458.12 In reply to 35458.11 
You obviously do want one, cos you're trying to pipe to a variable. Btw, does the 2.0 CTP have Linq support?

0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  THERE IS NO GOD BUT (RENDLE)     
35458.13 In reply to 35458.12 
It does if you've got .NET 3.5 installed.

Doesn't require 3.5 to use other stuff though.
0/0
 Reply   Quote More 

 From:  THERE IS NO GOD BUT (RENDLE)  
 To:  Peter (BOUGHTONP)     
35458.14 In reply to 35458.13 
Awesome. I've got to get that tomorrow.

0/0
 Reply   Quote More 

Reply to All    
 

1–14

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2024 Project Beehive Forum

Forum Stats