LingxB
LingxB

Reputation: 497

Batch script stops after output conda environment

I'm trying to write a batch script to export all available conda evnironments, after searching piece by piece on the internet, I came up with the following:

@echo off

conda info --envs > conda_envs.txt

for /f "usebackq tokens=1 delims= " %%a in ("conda_envs.txt") do (
    if not %%a==# conda env export -n %%a > %%a.yml
)

The problem is that the script stops after conda info --envs > conda_envs.txt, I've tried to add call in front of both the for loop and export command, but no luck. What did I do wrong?

Upvotes: 0

Views: 444

Answers (1)

LingxB
LingxB

Reputation: 497

Many thanks to npocmaka, michael_heath and SomethingDark in the comment section, I think the missing parentheses made the debug process harder. By adding call in front of conda does help! Below is a working version of the script:

@echo off

call conda info --envs > conda_envs.txt

for /f "usebackq tokens=1 delims= " %%a in ("conda_envs.txt") do (
    if not %%a==# call conda env export -n %%a > %%a.yml
)

PS: if the second call before conda env export... is not added, this would work as well.

Upvotes: 1

Related Questions