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!
The script sample is VBScript, not Powershell. Thus, you cannot execute it on Powershell. You can, however, execute it via invoking
cscript. There is alsowscriptthat executes VBScript, but it is used for graphics: popup windows and such. Rename the file as.vbsand run it. Like so,Cmd.exe uses the hat char as escape. Like so,
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.
… But I’d still do this in Powershell. Like so,