我正在尝试创建一个文件.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
答案 0 :(得分:0)
语法是:
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
参见&#34; How to create a file in Ruby&#34;可能重复。