【问题标题】:writing encoded content to .ps1 file将编码内容写入 .ps1 文件
【发布时间】:2017-10-08 02:40:47
【问题描述】:

我正在尝试创建一个文件 .ps1 并使用 ruby​​ 编写内容。但是我遇到了错误。下面是代码

output = File.open( "test.ps1", "w" )
  output << "$a = type c://edmundsapi-final ;(Get-Content C:\inetpub\sites\tsd_atlasapi\AppSettings.config) -replace '(?<=<add key="Edmunds" value=")[^"]*', $a | Set-Content C:\inetpub\sites\tsd_atlasapi\AppSettings.config "
 output.close

【问题讨论】:

标签: ruby powershell


【解决方案1】:

语法是:

File.open("test.ps1", w) {|f| f.write("$a = type c://edmundsapi-final ;(Get-Content C:\inetpub\sites\tsd_atlasapi\AppSettings.config) -replace '(?<=<add key="Edmunds" value=")[^"]*', $a | Set-Content C:\inetpub\sites\tsd_atlasapi\AppSettings.config ") } 

out_file = File.new("test.ps1", "w") 
out_file.puts("$a = type c://edmundsapi-final ;(Get-Content C:\inetpub\sites\tsd_atlasapi\AppSettings.config) -replace '(?<=<add key="Edmunds" value=")[^"]*', $a | Set-Content C:\inetpub\sites\tsd_atlasapi\AppSettings.config ")

out_file.close

请参阅“How to create a file in Ruby”了解可能的重复项。

【讨论】:

  • 我试过但给了我错误:SyntaxError c:/local-mode-cache/cache/cookbooks/tsd_atlasapi/recipes/default.rb:435: 语法错误,意外 tCONSTANT,期待 ')' ...ce '(?
  • 你需要检查你的报价
猜你喜欢
  • 1970-01-01
  • 2021-07-22
  • 2016-09-28
  • 2012-05-18
  • 1970-01-01
  • 1970-01-01
  • 2021-08-15
  • 2013-08-01
  • 2010-11-09
相关资源
最近更新 更多