Batch File Output Issue

江枫思渺然 提交于 2020-08-10 19:23:04

问题


I have a batch file which, if I run manually, produces a text file with a single number. However, if I schedule it with Task Scheduler, it produces an "error". Let me know if there is anything obvious that I am doing wrong.

Batch file:

rem Call mysql_start. bat which starts mysql and runs get_rain.bat and sends output to raw_totals.txt
call mysql_start.bat

rem Open raw_totals and remove 'raincounter' header
type C:\CumulusMX\cocorahs_reports\raw_totals.txt | findstr /v raincounter >     C:\CumulusMX\cocorahs_reports\raw_totals_no_header.txt

rem Calculate 7a-7a rain and send output to 7-7_rain.txt
setlocal enabledelayedexpansion
set cnt=1
for /f "usebackq" %%i in ("C:\CumulusMX\cocorahs_reports\raw_totals_no_header.txt") do (
   set var!cnt!=%%i
   set /a cnt+=1
)
(powershell %var1% - %var2%) > C:\CumulusMX\cocorahs_reports\output.txt
powershell exit


rem Delete raw_totals and raw_totals_no_header
del /f C:\CumulusMX\cocorahs_reports\raw_totals.txt
del /f C:\CumulusMX\cocorahs_reports\raw_totals_no_header.txt

"Error" output:

'-' was specified as the argument to -Command but standard input has not been redirected for this process.

PowerShell[.exe] [-PSConsoleFile <file> | -Version <version>]
[-NoLogo] [-NoExit] [-Sta] [-Mta] [-NoProfile] [-NonInteractive]
[-InputFormat {Text | XML}] [-OutputFormat {Text | XML}]
[-WindowStyle <style>] [-EncodedCommand <Base64EncodedCommand>]
[-ConfigurationName <string>]
[-File <filePath> <args>] [-ExecutionPolicy <ExecutionPolicy>]
[-Command { - | <script-block> [-args <arg-array>]
              | <string> [<CommandParameters>] } ]

PowerShell[.exe] -Help | -? | /?

(Cutting off for brevity)......

来源:https://stackoverflow.com/questions/62983420/batch-file-output-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!