![](/img/trans.png)
[英]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.