I am looking for help on how to call cmd with specific parameters from a powershell script. So far I have written below, but it gives me an error message saying that $ _cmd is not recognized.
I am trying to pass the date and date to exe ... From today, as you can see, it should be today - 1, and today it should be now. The executable path is D: \ DataService and therefore I set the path at the beginning of the script.
Write-Host "Get data from service" $path ="D:\DataService" Push-Location $path $Date = Get-Date $DateFrom = $Date.ToString("yyyy-MM-dd HH:mm:ss") $DateTo = $Date.AddDays(-1).ToString("yyyy-MM-dd") $_cmd = "ReportGen.exe -ReportType Data -DateFrom $DateFrom $DateTo" %$_cmd%
Any suggestions please?
Do not create a command line. Just use the call statement ( &):
&
Write-Host 'Get data from service' $path = 'D:\DataService' Push-Location $path $Date = Get-Date $DateFrom = $Date.ToString('yyyy-MM-dd HH:mm:ss') $DateTo = $Date.AddDays(-1).ToString('yyyy-MM-dd') & ReportGen.exe -ReportType Data -DateFrom $DateFrom $DateTo
Invoke-Expression .
Invoke-Expression
Invoke-Expression $_cmd
, :
. :.
& $_cmd
, %.
%
%$_cmd% PowerShell cmd. % . PowerShell , , , . ,
%$_cmd%
, ReportGen.exe , cmd , . - , , cmd, cmd /c cmd /k . , cmd :
cmd /c
cmd /k
cmd /c ReportGen.exe -ReportType Data -DateFrom $DateFrom $DateTo
/c , cmd . /k , cmd . , /c, PowerShell script.
/c
/k
. , Write-Host. , , - ( - , ). Write-Output - , script . -, Start-Process -ArgumentList.
$DateFrom $DateTo , $DateTo . , , . , , , , , , . , Invoke-Command , :
Invoke-Command -FilePath "D:\DataService\ReportGen.exe" -ArgumentList '-ReportType Data','-DateFrom $DateFrom','$DateTo'
.
$CustomProcess = New-Object System.Diagnostics.ProcessStartInfo $CustomProcess.FileName = "ReportGen.exe" $CustomProcess.arguments = "-ReportType Data -DateFrom $DateFrom $DateTo" [System.Diagnostics.Process]::Start($CustomProcess)
Source: https://habr.com/ru/post/1524320/More articles:Idiomatic Clojure Python crop imitation method - pythonNewSingleThreadScheduledExecutor working if thread is already busy - javahttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1524317/laravel-how-to-prefix-all-json-responses-to-protect-against-json-injection&usg=ALkJrhiELUgfjnSYghbnHY_qqc5mN6KCeAWhy can I close the style tag from CSS comments? - htmlhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1524319/laravel-how-to-prefix-all-json-responses-to-protect-against-json-injection&usg=ALkJrhgkUj6EVb7DG74kGtT1ZezGeDXtEAHow to check compliance with FakeItEasy on a predicate call? - c #Не удалось удалить один из нескольких прослушивателей событий в представлении Backbone.js - javascriptBackbone.js Просмотр отключений событий - backbone.jsHow to make a square of an android image? - androidFailed to resolve placeholderAll Articles