我有一个文本文件,其中我有一个其他文件的引用。我想要做的是运行一个脚本,它将在运行时用文件的内容替换文件名,然后将其卷曲到服务器。用文件内的文件内容替换文件名在windows中
任何人都可以推荐一个快速的方法来使用PowerShell或类似的东西在Windows命令行上做到这一点?
例如
"responses": [
{
"is": {
"statusCode": 200,
"headers": {
"Location": "http://localhost:4545/myresponse",
"Content-Type": "application/xml"
},
"body": "@file:myresponse.xml"
}
}]
将成为:
$template = Get-Content template.txt -Raw
$template = [regex]::Replace($template, '(@file:.*?)(?=")', {param($f) Get-Content ($f -replace '@file:') -Raw }))
Invoke-WebRequest -Uri 'http://example.org/' -ContentType 'application/json' -Method Post -Body $template
....根据您的设置的所有细节:
"responses": [
{
"is": {
"statusCode": 200,
"headers": {
"Location": "http://localhost:4545/myresponse",
"Content-Type": "application/xml"
},
"body": "<xml> contents of myresponse.xml within same directory.. </xml>"
}
}]
你是否知道PoSh与“windows命令行”无关? - powershell.exe aint PoSh;) –
是的..我不是一个有经验的Windows脚本编写者,但是我认为使用普通命令行脚本相比PowerShell非常困难,但希望保持我的选项开放:) – Pete