[英]Add the result of a Powershell Start-Process to a file instead of replacing it with -RedirectStandardOutput
[英]Using Start-process to kick off a LogParser process, error encountered
我正在使用以下代碼嘗試使用Log Parser觸發並將我擁有的.csv文件的內容轉儲到SQL數據庫中。 我不得不嘗試使用自定義函數來去除非字母數字字符,以便可以動態創建列,因為最終目的是要對我提供的任何.csv文件進行此項工作。
這是代碼:
start-process -NoNewWindow -FilePath "C:\Program Files (x86)\Log Parser 2.2\LogParser.exe" -ArgumentList @"
"Create Function [dbo].[RemoveNonAlphaNumCharacters](@Temp VarChar(1000))
Returns VarChar(1000)
AS
Begin
Declare @KeepValues as varchar(50) = '%[^a-z0-9]%'
While PatIndex(@KeepValues, @Temp) > 0
Set @Temp = Stuff(@Temp, PatIndex(@KeepValues, @Temp), 1, '')
Return @Temp
End
SELECT.RemoveNonAlphaNumCharacters * INTO SQLCounters FROM C:\Users\SeanLon\Desktop\SQL_Log_0.csv" -i:CSV -o:SQL -server:MJNHNX4 -database:PerfmonCounters -driver:"SQL Server" -createTable:ON
"@
錯誤:
start-process : Process with an Id of 221104 is not running.
At C:\Users\seanlon\Desktop\Performance\Powershell examples\LogParser.ps1:1 char:1
+ start-process -NoNewWindow -FilePath "C:\Program Files (x86)\Log Parser 2.2\LogP ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Start-Process], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.StartProcessCommand
啟動進程或日志解析器可以簡單地不處理參數列表中的那種復雜的SQL嗎? 還是LogParser進程在其他事情發生之前就關閉了?
在PowerShell 3.0上,它看起來像是在干凈地傳遞參數。 但是,為簡化此操作,您可以將SQL放在文件foo.sql中,然后像這樣調用logparser:
$logParser = "C:\Program Files (x86)\Log Parser 2.2\LogParser.exe"
& $logParser file:c:\foo.sql -i:CSV -o:SQL -server:MJNHNX4 -database:PerfmonCounters -driver:"SQL Server" -createTable:ON
LogParser對數據庫一無所知,它在其內部引擎(不處理存儲過程)中解釋並執行簡單的SQL查詢。 另請參閱Logparser無法識別SQL命令 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.