CMD executes powershell command to continuously log (tail) a file but does not return back to cmd or execute next command

I am using CMD to execute PowerShell command for logging (tailing a data file “trun.out” that updates from a simulation run). > See the “Call start Poweshell” portion of the code below.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>if %therm%==y (del /f trun.out
fsutil file createnew trun.out 8192
CALL start powershell -noninteractive -File "trun_tail_powershell.ps1"
if %dist_solve%==1 (%ans_path% -b -dis -np %num_proc% -j %job% -run %run% -i therm.inp -o trun.out) else (%ans_path% -b -dis -np %num_proc% -f -m 30000 -db 5000 -j $job -run %run% -i therm.inp -o trun.out)
REM END
)
dir
</code>
<code>if %therm%==y (del /f trun.out fsutil file createnew trun.out 8192 CALL start powershell -noninteractive -File "trun_tail_powershell.ps1" if %dist_solve%==1 (%ans_path% -b -dis -np %num_proc% -j %job% -run %run% -i therm.inp -o trun.out) else (%ans_path% -b -dis -np %num_proc% -f -m 30000 -db 5000 -j $job -run %run% -i therm.inp -o trun.out) REM END ) dir </code>
if %therm%==y (del /f trun.out
    fsutil file createnew trun.out 8192
    CALL start powershell -noninteractive -File "trun_tail_powershell.ps1"
    if %dist_solve%==1 (%ans_path% -b -dis -np %num_proc% -j %job% -run %run% -i therm.inp -o trun.out) else (%ans_path% -b -dis -np %num_proc% -f -m 30000 -db 5000 -j $job -run %run% -i therm.inp -o trun.out)   
    REM END 
    )
dir 

After the if statement is executed, a new powershell window opens (it is done purposefully so that the data logging can be seen separately). Logs the trun.out data file.

However, CMD does not execute “dir” command right after the if statement.

I first thought that CMD opening a new powershell window for data logging does not returns the authority (not sure if this is the correct word to use) back to CMD to move on to the next command, so I tried commenting the data logging section and not creating any powershell window. But I am still having the issue. It does not execute anything after the if statement.

But if I place the “dir” command inside if statement, it will show the directory.

Would appreciate any help/guidance as I am quite new using CMD and powershell altogatehr.

9

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>if "%therm%"=="y" (
del /f trun.out
fsutil file createnew trun.out 8192
start /wait powershell -noninteractive -File "trun_tail_powershell.ps1"
if "%dist_solve%"=="1" (
"%ans_path%" -b -dis -np "%num_proc%" -j "%job%" -run "%run%" -i therm.inp -o trun.out
) else (
"%ans_path%" -b -dis -np "%num_proc%" -f -m 30000 -db 5000 -j "%job%" -run "%run%" -i therm.inp -o trun.out
)
REM END
)
dir
</code>
<code>if "%therm%"=="y" ( del /f trun.out fsutil file createnew trun.out 8192 start /wait powershell -noninteractive -File "trun_tail_powershell.ps1" if "%dist_solve%"=="1" ( "%ans_path%" -b -dis -np "%num_proc%" -j "%job%" -run "%run%" -i therm.inp -o trun.out ) else ( "%ans_path%" -b -dis -np "%num_proc%" -f -m 30000 -db 5000 -j "%job%" -run "%run%" -i therm.inp -o trun.out ) REM END ) dir </code>
if "%therm%"=="y" (
    del /f trun.out
    fsutil file createnew trun.out 8192
    start /wait powershell -noninteractive -File "trun_tail_powershell.ps1"
    if "%dist_solve%"=="1" (
        "%ans_path%" -b -dis -np "%num_proc%" -j "%job%" -run "%run%" -i therm.inp -o trun.out
    ) else (
        "%ans_path%" -b -dis -np "%num_proc%" -f -m 30000 -db 5000 -j "%job%" -run "%run%" -i therm.inp -o trun.out
    )
    REM END 
)
dir
  • Compo is right, CALL shouldn’t be in your script. it should be used when you want to call another batch file from within your script.

  • I think the issue is the start command, you want to use the start/wait command instead. The start command opens a new cmd prompt window without waiting for the window to close but with start/wait, the new window closes before the next command executes

  • Also i noticed inside your else clause, you have $job instead of %job%.

Hopefully, this helps.

To modify the code to running ansys through cmd with the following code as discussed in the comment. %ans_path% -b -dis -np %num_proc% -j %job% -run %run% -i therm.inp -o trun.out. try this

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>if "%therm%"=="y" (
del /f trun.out
fsutil file createnew trun.out 8192
start powershell -noninteractive -File "trun_tail_powershell.ps1"
if "%dist_solve%"=="1" (
cmd /c "%ans_path% -b -dis -np %num_proc% -j %job% -run %run% -i therm.inp -o trun.out"
) else (
cmd /c "%ans_path% -b -dis -np %num_proc% -f -m 30000 -db 5000 -j %job% -run %run% -i therm.inp -o trun.out"
)
REM END
)
dir
</code>
<code>if "%therm%"=="y" ( del /f trun.out fsutil file createnew trun.out 8192 start powershell -noninteractive -File "trun_tail_powershell.ps1" if "%dist_solve%"=="1" ( cmd /c "%ans_path% -b -dis -np %num_proc% -j %job% -run %run% -i therm.inp -o trun.out" ) else ( cmd /c "%ans_path% -b -dis -np %num_proc% -f -m 30000 -db 5000 -j %job% -run %run% -i therm.inp -o trun.out" ) REM END ) dir </code>
if "%therm%"=="y" (
    del /f trun.out
    fsutil file createnew trun.out 8192
    start powershell -noninteractive -File "trun_tail_powershell.ps1"
    if "%dist_solve%"=="1" (
        cmd /c "%ans_path% -b -dis -np %num_proc% -j %job% -run %run% -i therm.inp -o trun.out"
    ) else (
        cmd /c "%ans_path% -b -dis -np %num_proc% -f -m 30000 -db 5000 -j %job% -run %run% -i therm.inp -o trun.out"
    )
    REM END 
)
dir

6

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật