0

I have a batch file that loops every second checking existence of a file. If it exists, bat calls another executable to format and send the contents over serial port and deletes the file afterwards. The problem is that the user must press a button on the linked hardware after the transfer is done, but there is no progress report on either side.

It appears that the sending is called synchronously (theSoft.exe send commandFile.dat) unless the executable spawns another thread itself.

I decided I could modify the bat to open a window (probably an instance of cmd) and print "Transferring data, please wait" before starting the sending. After the sending is complete it should print "Sending done", leave it up for a second or two and close the window afterwards. But this seems quite hard in windows. I can easily spawn a new window of cmd using start and echo a text. But the window seems "lost" in the very next moment - how could I refer to the same window after some other lines are done and send additional commands to it (echo another text, wait a bit and close)?

Note: I am not the developer of this setup, the inner workings of most components are out of my reach. The only options seems to be modifying this bat or sniffing the serial port for traffic which seems to involve a lot more work.

Džuris
  • 2,115
  • 3
  • 27
  • 55
  • I've never done a thing like this, but sure that new prompt instance have a pid associated, I would start there. I was recommended to never delete files after a transfer, but moving them to a backup directory just in case. I hope this might help. – SNR Jun 03 '19 at 11:54
  • Is there any documentation for `theSoft.exe`? What does `theSoft.exe /?` say? – Stephan Jun 03 '19 at 13:24
  • How exactly does `theSoft.exe` work when you execute it directly on the command line? (Any output? Does the prompt come back immediately or only when the transfer is complete?) – Stephan Jun 03 '19 at 13:33
  • Just [run](https://stackoverflow.com/a/24725044/3074564) with command `start` one more batch file with current file name as first and only argument. The second batch file outputs the message, then checks in a loop every second (or every three or five seconds) if the file passed by main batch file via first argument does not exist anymore to exit the loop. Next the `Sending done.` message is output and `%SystemRoot%\System32\timeout.exe /T 5` is used to wait up to five seconds more before the batch file processing ends by separate command process as no more line in second batch file. – Mofi Jun 03 '19 at 17:31
  • The second batch file can be started by main batch file with the file name concurrent as often as needed. It is even possible to use only one batch file. If the batch file is started with no argument, it runs endless to do the main job. If the batch file starts itself with command `start` with file name as argument, it jumps to a code block below endless running code to output the first message, wait for deletion of passed file by main instance of batch file, outputs second message, waits some seconds and ends. Multiple `cmd.exe` can run same batch file concurrent multiple times. – Mofi Jun 03 '19 at 17:42

0 Answers0