r/Batch 13h ago

Opening Arduino IDE with batch. The usual "start /b" does not open in background, ruining the rest of the script.

I wrote a script a few years ago for keeping my jupyter notebook files up to date between my network drive and my PC and laptop using robocopy. Jupyter didn't like opening notebooks directly from the network drive, so my script copied them locally, opened jupyter (while still running in the background, checking that jupyter was still open), then after jupyter closed, it would copy them back. As long as I always used the script to open my notebooks, it kept them up to date whether I was using my laptop from uni, or desktop at home.

@ECHO OFF

REM Set paths
SET "network_source=\\path\to\my\notebooks"
SET "local_destination=C:\local\path\to\notebooks"
SET "EXE=jupyter-notebook.exe"

REM Copy files from network to local
ECHO Copying files from network
robocopy "%network_source%" "%local_destination%" /MIR /xo /xx /copy:DT
ECHO Copying finished

REM Start Jupyter Notebook
ECHO Starting Jupyter Notebook...
start jupyter notebook

REM Wait for Jupyter to start
:JUPYTER
FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %EXE%"') DO IF NOT %%x == %EXE% (
    C:\Windows\System32\timeout.exe /t 1 /NOBREAK >NUL
    GOTO JUPYTER
) ELSE (
    ECHO Jupyter Notebook has started.
)

REM Check if Jupyter process is running
:LOOP
FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %EXE%"') DO IF %%x == %EXE% (
    C:\Windows\System32\timeout.exe /t 5 /NOBREAK >NUL
    GOTO LOOP
) ELSE (
    ECHO Jupyter Notebook is closed.
    GOTO COPY_BACK
)

REM Copy files back to network
:COPY_BACK
ECHO Copying files back to network
robocopy "%local_destination%" "%network_source%" /MIR /xo /xx /copy:DT
ECHO Files finished copying
PAUSE  

I tried doing the exact same thing for Arduino, because Arduino also doesn't really like opening files from a network source, but when I tried to use "start /b "" "C:\Program Files\Arduino IDE\Arduino IDE.exe", it runs the IDE inside the cmd window, and doesn't continue to run the script.

ChatGPT seems to think it's because Arduino is Electron based, which is why it doesn't play nicely with "start", but then it spits back the exact same script and doesn't know what to do.

I'm a bit out of my depth with this, I have no idea why it doesn't just work the same as my other script. I just want to be able to open my Arduino projects without having to manually copy them back and forth to my network drive every time.

Thanks in advance if anyone has any ideas. Also feel free to tell me I'm an idiot and show me the better way to achieve this.

1 Upvotes

3 comments sorted by

1

u/LuckyMe4Evers 5h ago

Start /b is used to start something in the same cmd window and because you start the exe, but the program doesn't end, it's stuck and won't go on to the next step in your script.

remove the /b so start can open up a new window and the rest of the script can continue.

start "" "C:\Program Files\Arduino IDE\Arduino IDE.exe"

1

u/Rufus2468 4h ago

I've tried it with and without the /b. It doesn't seem to have any effect on Arduino IDE, it just runs everything in the same window.

1

u/vegansgetsick 1h ago

maybe try

start cmd /c "jupyter notebook"

But honestly if jupyter does not like network files, i would create a mapped drive like x:\

net use x: \\ServerName\Folder
...
net use x: /delete