Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8853871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:45:11+00:00 2026-06-14T13:45:11+00:00

I’m newb in powerShell and in cmd, sorry. I’m trying write script that can

  • 0

I’m newb in powerShell and in cmd, sorry.
I’m trying write script that can generate define like this

#define VERSION "a89aa153a054b865c0ef0a6eddf3dfd578eee9d2"

in VERSION i want to set the parameter from next source

.git\refs\heads\project

I’m tried next cmd script, but i have problems with ” character, i can’t escape it

echo #define VERSION \" > ver.h
type .git\refs\heads\project >> ver.h
echo \" >> ver.h

Also i’m tried use script from that post http://blogs.technet.com/b/heyscriptingguy/archive/2008/04/29/how-can-i-read-a-text-file-and-extract-all-the-text-enclosed-in-double-quote-marks.aspx

but i have a problems when i’m trying to run it.
i’m created file writeDefine.ps1

Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("D:\Scripts\DefineTemplate.txt", ForReading)

Do Until objFile.AtEndOfStream
    strText = ""
    strCharacter = objFile.Read(1)
    If strCharacter = Chr(34) Then
        Do Until objFile.AtEndOfStream
           strNewCharacter = objFile.Read(1)
           If strNewCharacter = Chr(34) Then
               Exit Do
           End If
           If strNewCharacter <> "" Then
               strText = strText & strNewCharacter
           End If
        Loop
        Wscript.Echo strText
    End If
Loop

objFile.Close

i want to read template and insert VERSION between ” characters and write that text to the “ver.h”, but
i have got an error

D:\writeHeader.ps1:4 symbol:67
+ Set objFile = objFSO.OpenTextFile("D:\Scripts\DefineTemplate.txt", <<<<  ForReading)
    + CategoryInfo          : ParserError: (,:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingExpressionAfterToken 

DefineTemplate.txt

#define VERSION ""

Please, help me. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:45:13+00:00Added an answer on June 14, 2026 at 1:45 pm

    The script sample is VBScript, not Powershell. Thus, you cannot execute it on Powershell. You can, however, execute it via invoking cscript. There is also wscript that executes VBScript, but it is used for graphics: popup windows and such. Rename the file as .vbs and run it. Like so,

    cscript d:\writeHeader.vbs
    

    Cmd.exe uses the hat char as escape. Like so,

    C:\temp>echo #define VERSION ^" > ver.h
    C:\temp>type ver.h
    #define VERSION "
    

    Edit: As per how to create the header on a single line, some trickery must be invoked. This would be much more simple in Powershell, but here goes.

    :: Assume git data is in git.dat and it doesn't contain a newline
    echo ^"> quote.txt
    <nul set /p d=#define VERSION ^"> ver.h
    copy /y ver.h+git.dat+quote.txt ver2.h
    type ver2.h
    #define VERSION "0x000..."
    

    … But I’d still do this in Powershell. Like so,

    $git = cat .git\refs\heads\project # Read the git project file
    $str = $("#define VERSION `"{0}`"" -f $git) # Build a formatted string
    set-content -LiteralPath ver.h -value $str # Write the string to a file
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I am trying to render a haml file in a javascript response like so:
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to create an if statement in PHP that prevents a single post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.