4

Currently I have a batch file running:

cd "C:\Users\chriscrutt\Desktop\"
:loop
Start /w yeet.bat
goto loop

This runs "yeet.bat". Sometimes the command prompt will crash but I need it to automatically restart. That is why I used "/w" but it requires me to manually input "N" when it asks: Terminate batch job (Y/N)? Is there a way to make it so it automatically restarts or so it will automatically say "N" to restart it?

This is how it goes. I run the bat file which runs the yeet file which runs the other program. the code for "yeet.bat" is

title ETHBTC
cd "C:\Users\chriscrutt\Google Drive\gekkoETHBTC"
node gekko

When i do "node gekko" it runs the bot.

chriscrutt
  • 500
  • 3
  • 5
  • 17
  • 1
    You need to give us more information about yeet.bat, preferably with its content and what you mean by sometimes it crashes. _I'd wager that what is crashing is an external utility/executable._ – Compo Mar 15 '17 at 21:29
  • It is a bot that scans bitcoin exchange markets and suggests trades to you. It requests and stores information of the prices at which bitcoins are bought and sold at. When it crashes, I just need it to start up again ASAP so it can continue to scan the market. I don't think it matters how it crashes, I just need it to start back up immediately and automatically. – chriscrutt Mar 15 '17 at 21:41
  • 1
    Try : CALL yeet.bat – Squashman Mar 15 '17 at 21:51
  • I do agree with @Compo. Would probably help to see yeet.bat – Squashman Mar 15 '17 at 21:59
  • It doesn't open in a separate window with "call" so if it closes it won't restart – chriscrutt Mar 15 '17 at 22:00
  • I revised my question above to give more information, if you would like to see the "gekko" files, go to https://github.com/askmike/gekko – chriscrutt Mar 15 '17 at 22:07
  • A path needs to be quoted if it contains a special character such as a space. `cd "C:\Users\chriscrutt\Google Drive\gekkoETHBTC"` – lit Mar 15 '17 at 22:18
  • @lit it doesn't need a space if it's given to the `cd` command. The `cd` command takes only one parameter, so it treats the whole line as a single parameter, spaces and all. – Klitos Kyriacou Mar 15 '17 at 22:34
  • So did you install your bot to your Google Drive folder? – Compo Mar 15 '17 at 22:35
  • Have you tried `start /b`? It disables control-C processing, which is probably what is causing the "Terminate batch job?" prompt. – Klitos Kyriacou Mar 15 '17 at 22:38
  • using /b just made it run hundreds of instances on the same window... somehow lol, and i just installed it by cutting and pasting the file into google drive. – chriscrutt Mar 15 '17 at 22:58
  • You need the `/w` (wait) option too. `start /b /w`. – Klitos Kyriacou Mar 15 '17 at 22:59
  • now it won't open into another window, so when it exits it wont start up again – chriscrutt Mar 15 '17 at 23:03
  • But why would it exit in the first place? You don't need another window. Your batch file is in a loop, so when the app exits, the batch file will go back to the start of loop. – Klitos Kyriacou Mar 15 '17 at 23:09
  • idk why it exits sometimes, I just go back on my computer and the command prompt is gone. I did a little research and on git they said it crashes sometimes. idk if it is the prompt exiting or just the app failing, which would trigger /b. If it is the prompt exiting I wanted another prompt open that would immediately re-execute the file so it would run again. – chriscrutt Mar 15 '17 at 23:14
  • Are you sure you have [installed it correctly](https://github.com/askmike/gekko#installing-gekko) and have all of the dependencies with the proper configuration etc. – Compo Mar 15 '17 at 23:29
  • haha everything is fine, just once in awhile it crashes. At this point im just curious to see if there is a way to restart a bat file from another – chriscrutt Mar 15 '17 at 23:37
  • Can you not check if the bot executable process is running okay, and just stop/restart it if it isn't. – Compo Mar 15 '17 at 23:48
  • automatically with a batch? The process id wouldn't change if i ran it and exited and ran it again? If i ran more than one cmd.exe i couldn't restart it using the process name either. – chriscrutt Mar 16 '17 at 00:01
  • Not sure if this will help, your `yee.bat` should avoid `cd`, otherwise you can't call `yee.bat` again, because your working directory has changed. Instead, just call the `"C:\Users\chriscrutt\Google Drive\gekkoETHBTC\node gekko"` directly in your `yee.bat` – kurakura88 Mar 16 '17 at 03:59

1 Answers1

6

This code do what you want: each time that yeet.bat ends for any reason it is restarted again "immediately and automatically".

cd "C:\Users\chriscrutt\Desktop\"
:loop
Start yeet.bat | set /P "="
goto loop
Aacini
  • 65,180
  • 12
  • 72
  • 108
  • I really would like to know the reason because someone downvoted this answer. If it was because the lack of explanations, I assumed that the operation of `|` pipe and `set /P` command are known by all Batch file users. If a further explanation is wanted, just ask for it! **`:(`** – Aacini Mar 16 '17 at 19:55
  • Haven't a clue why the down vote. You got my up vote the moment I saw and tested the answer. – dbenham Mar 18 '17 at 16:56
  • @dbenham: **`:)`** I invite you to review [this answer](http://stackoverflow.com/questions/42869222/batch-file-auto-quits-i-cant-find-the-error/42874804#42874804) – Aacini Mar 18 '17 at 16:59
  • I'm curious what the `| set /P "="` does, without it I see that it just infinitely spawns the other batch file. – captDaylight Aug 30 '19 at 20:08
  • 1
    Possibly the downvoter had an issue with ``| set /P "="`` I tried it but wouldnt work, but removing the quotations only then would work. What made it fail was the quotation marks interfere with goto statement – Gareth Compton Jan 19 '20 at 18:27