What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 134 Stack Exchange communities.

This question already has an answer here:

From http://stackoverflow.com/questions/2609985/how-to-run-a-powershell-script-within-a-dos-batch-file/2611487#2611487

There's an idiom in CMD scripts to use :: as a comment delimiter. (: means a label, so :: gets ignored.) I use it because I think it's easier to read than REM.

I wrote this in an answer:

@@:: This prolog allows a PowerShell script to be embedded in a .CMD file.
@@:: Any non-PowerShell content must be preceeded by "@@"
@@setlocal
@@set POWERSHELL_BAT_ARGS=%*
@@if defined POWERSHELL_BAT_ARGS set POWERSHELL_BAT_ARGS=%POWERSHELL_BAT_ARGS:"=\"%
@@PowerShell -Command Invoke-Expression $('$args=@(^&{$args} %POWERSHELL_BAT_ARGS%);'+[String]::Join(';',$((Get-Content '%~f0') -notmatch '^^@@'))) & goto :EOF

which formatted like this (as of 9 April 2010; red circle added): alt text

share|improve this question

marked as duplicate by Manishearth, hims056, ben is uǝq backwards, Tobias Kienzler, Danny Beckett Jul 3 '13 at 12:38

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
5  
-1 for not using a freehand circle –  Mark Henderson Apr 12 '10 at 2:18
    
That's 5 issues with code formatting so far; there are surely more. I hope the SO team steps back and looks at the big picture, especially since SO is about programming so making code look good is important! –  Jay Bazuzi Apr 14 '10 at 18:06
1  
This question appears to be off-topic because it is about an issue with Google Prettify and cannot be addressed by the SE Development team. –  Manishearth Jul 3 '13 at 8:31

2 Answers 2

the SO syntax highlighter is not a magical language detector. It uses simple rules for colorization that happens to work decently with most languages. PowerShell is apparently not one of them.

share|improve this answer
    
Yeah, I get that SO's syntax highlighter is general-purpose that way. Note that the issue here is with CMD, not with PowerShell. (When I read what you wrote, I think you are telling me I shouldn't have reported this issue. Do you think the SO team doesn't want to know about it?) –  Jay Bazuzi Apr 11 '10 at 18:44
    
@Jay, I think this will be closed as a will-not-fix or by-design bug. The SO team has better things to do than change it so it works with CMD or Powershell or any other language perfectly. Plus, any changes to the highlighting engine at this point would cause old posts to highlight differently, possibly for the worse. If you want perfect syntax highlighting, put it on pastebin.com or similar. –  Earlz Apr 12 '10 at 1:59
1  
will-not-fix is fine; the StackOverflow team gets to decide where to put their energy. by-design seems nuts: who would say that this behavior is desirable? As for back-compat, it would be possible to teach the formatter to apply old rules to posts before a certain date, and new rules to newer posts. Again, up to the SO team to decide what they want to do. –  Jay Bazuzi Apr 14 '10 at 18:00
    
@Jay that just adds a lot of complicated implementation details for very little real benefit. If you want that, go cast your vote for that feature-request for a language selector for code formatting –  Earlz Apr 14 '10 at 21:31

You can do something similar to what the VB crowd does:

@@::// This prolog allows a PowerShell script to be embedded in a .CMD file.
@@::// Any non-PowerShell content must be preceeded by "@@"
@@setlocal
@@set POWERSHELL_BAT_ARGS=%*
@@if defined POWERSHELL_BAT_ARGS set POWERSHELL_BAT_ARGS=%POWERSHELL_BAT_ARGS:"=\"%
@@PowerShell -Command Invoke-Expression $('$args=@(^&{$args} %POWERSHELL_BAT_ARGS%);'+[String]::Join(';',$((Get-Content '%~f0') -notmatch '^^@@'))) & goto :EOF

@@::# will also work.

Not a great solution, but you can render the code properly.

share|improve this answer
    
Thanks, that's a good tip to know. This is an excellent example of "Each design pattern is a sign of a weakness in the programming language to which it applies". –  Jay Bazuzi Apr 14 '10 at 18:02

Not the answer you're looking for? Browse other questions tagged .