【问题标题】:How can I do parallel processing in batch?如何批量进行并行处理?
【发布时间】:2020-06-15 14:50:22
【问题描述】:

我想开始一个下标来为我计算一些东西,如果它完成了以某种方式返回值。

foo.bat:

@echo off
start bar.bat 2 3
::This foo.bat does something and after a while it waits for the calculated value.
set result=//somehow return the value
echo %result%
pause
exit

bar.bat:

@echo off
set int1=%1
set int2=%2
set /a result=%int1%+%int2%
::somehow send the result to the running foo.bat
exit

我试图问这个问题here,但我被三个人重定向到 call 函数,这不是我需要的(在我看来)。

【问题讨论】:

标签: windows batch-file cmd parallel-processing parameter-passing


【解决方案1】:

试试看:

主批处理文件

CALL sub_batch_file.bat  return_here "Second parameter input"

REM echo is Second parameter input
ECHO %return_here%
REM End of main-batch file

sub_batch_file.bat

@ECHO OFF
SETLOCAL

REM ~ removes the " "
SET input=%~2
(
    ENDLOCAL
    SET %1=%input%
)
exit /b
REM End of sub-batch file

【讨论】:

  • 这正好相反。我想为我的项目使用超过 1 个线程,因为它比这个例子复杂得多。如果我正确地知道它,这个解决方案将只能从调用者 cmd.exe 运行。这不是我想要的。
  • 那么你想要一个返回值的多线程脚本吗?你想让他们在使用所有结果之前完成所有工作吗?我真的不明白你为什么要这样做,你能解释一下,我会给你更多的帮助
猜你喜欢
  • 1970-01-01
  • 2019-05-26
  • 2014-12-03
  • 2021-11-08
  • 2014-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多