Jump to content

SkySurveyBanner.jpg.21855908fce40597655603b6c9af720d.jpg

command batch file help


Recommended Posts

NINA in the advanced sequencer allows for a .bat file to be inserted and run

I have a .bat script that sends via a com port a command to open and close a relay. This batch file when run directly from the documents folder shows the terminal screen and displays all my echo text and opens and closes the relay and closes the terminal when done.

When called from NINA the terminal screen is shown and the batch file runs properly in the background but the terminal just shows the CMD and a flashing cursor then exits when the batch file is done. No echo's are shown.

I can live with the way it works now but are there any  MSDOS experts out there who can point me to the command to make it display the script?

I have tried all kinds of Google searches but nothing seems to fit this problem

 

I am beginning to think this is a NINA issue as Sharpcap 4.0 sequencer has the same run batch file facility and it runs my batch file normally i.e. it shows on the console all my echo's for script progress.

Edited by Tomatobro
more info
Link to comment
Share on other sites

I'm a bit rusty on DOS but I think your problem lies in that your batch file is called from a "higher" process, so all "echos" are being sent back to it rather than the screen. You need to redirect it (using the redirect >) to the screen, which I can't recall window's term for. However, I know a man who probably knows the answer. If no-one gets back sooner, hang fire coz I'm seeing him this evening!

  • Thanks 2
Link to comment
Share on other sites

Funnily enough I have some power switches coming today that can be controlled from the command line that I'm intending to use in NINA end sequence scripts so I just wrote a quick batch file to try myself and you're right, of course. Don't have an answer yet though 🙂

  • Like 1
Link to comment
Share on other sites

As I say its not the end of the world because when the batch file runs I should be tucked up in bed fast asleep.......

So no one will be their to read the screen anyway but for completeness it would be good to have it run as it should

  • Like 1
Link to comment
Share on other sites

Just in case anyone was wondering, @Tomatobro has embarked on this exercise to allow NINA to operate two HITEC Focusmasters (old black box type) on a dual rig since NINA will only recognise a single unit when two are connected.

Link to comment
Share on other sites

30 minutes ago, tomato said:

Just in case anyone was wondering, @Tomatobro has embarked on this exercise to allow NINA to operate two HITEC Focusmasters (old black box type) on a dual rig since NINA will only recognise a single unit when two are connected.

Aren’t you running two instances of NINA though?

Link to comment
Share on other sites

Tomato has an older Pulsar dome for which we built the dome control. We use Rf solutions modems to do two way communication to the dome (all electronics rotate with the dome)

As we make changes to the controls to allow for unattended imagining we need for Nina to run on one laptop. The idea is that NINA will do focusing on scope A then run a script that will switch the usb port to the other focuser if FWH changes. then run focusing and then switch back. We also will be able to close the shutter at sequence end rather that rely on a timer. Other changes are planned such as stop on  cloud detection etc

Link to comment
Share on other sites

I think this would work and I have used this to good effect when doing synchronised dithering on the dual rig,  but will NINA synchronise other events in a sequence across two instances?

The problem I have is the master scope with the OAG stops guiding to refocus  so the slave scope has to stop imaging and ideally run the refocus routine at the same time. The trouble is the subs download faster on the master scope compared to the slave (it’s a camera thing I think) so they can be quite a few seconds adrift after say 30 subs. I suppose I could time the delay and if consistent build a pause routine into sequence 1, although this wouldn’t work if other criteria were used to trigger a refocus.
I think I would rather have the focus routines run sequentially, on one instance of NINA especially as the autofocus routine duration cannot be guaranteed to be the same each time.

Link to comment
Share on other sites

Questions:

1) Is it the case that the "echoes" are disappearing simply because the batch file has run and hence the command window gets closed?

2) How does NINA run the batch file? (Bear in mind I have zero experience of NINA, the limit of my knowledge is that I've heard of it!)

I spoke to my friend and we suspect (1) above applies.

Link to comment
Share on other sites

1) when the batch file is called from the directory where it is stored (documents) it displays the terminal screen and it runs properly. Shows things like the timeout counter counting down etc.

Both NINA and Sharpcap have provision in the sequencer to set up a path to a batch file and will run the batch file when it is called. When the batch file is completed the terminal screen closes and returns to the next step in the sequence. The difference is that when called by NINA the command terminal opens but does not display the information (like the countdown timer) but is just a terminal with a flashing cursor. However, by watching the output to the serial port I can see that the batch file is running in the background, and when finished the terminal screen closes and NINA then goes to the next step in the sequence

2) In the advanced sequencer you pull across the bar from the menu and type in the path to the batch file

Why clicking directly on the batch file it runs AND displays the progress but called from NINA it runs but the progress is not displayed seems odd as control is passed to the same bit of DOS code.

Hope this clarifies but I will try to capture and post both terminal screens if it helps

Link to comment
Share on other sites

@Tomatobro beat me too it but I can confirm if we run the batch file from windows, all of the text is displayed in the DOS console window, but if you run the same batch file from NINA, the console window opens but no text is displayed. The file has executed all of the other commands but does not display the text. There are timeout steps in the file so it's not running that fast that you don't see the text, you just get a blank console window with a flashing cursor until the batch file has been executed, then it closes.

Link to comment
Share on other sites

When calling another process - calling process has the control of I/O handles. It can decide what to do with standard output from the sub process.

You can't force display on cmd prompt that is opened. There are two options from the top of my head:

1. Look in Nina documentation if there is a way to examine standard output of script in real time - like opening log window or similar. This is standard way to do things - either calling process discards output or stores it / shows it somehow (even cmd.exe is actually printing our output of other processes that just simply write to standard output handle)

2. Instead of printing to screen - consider some sort of independent log server where script will "print" or rather send log

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Simplest way seems to be to alter .bat file in following way:

whenever you want to write or "echo" something to standard output - you make redirect to a file instead and just watch that file in another window:

In batch file instead of commands:

echo "I'm doing something interesting here"

change to

echo "I'm doing something interesting here" > c:\output.txt

Then in windows powershell use this:

Get-Content c:\output.txt –Wait

 

  • Like 1
Link to comment
Share on other sites

These two screen shots show the difference between the two terminal screens. Don't worry about the illegal com port it was not connected.

Capture1 is when the batch file is called direct and capture 2 is when called via NINA. For both screens the batch file is running successfully.

capture1.JPG

Capture2.JPG

Link to comment
Share on other sites

Just now, scotty38 said:

Yes you can pipe to a file for later review that’s easy enough. For real time review I asked on discord if NINA is running it silently but not had an answer yet. 

Code for that is here:

https://bitbucket.org/Isbeorn/nina/src/v1.10.1/NINA/Utility/ExternalCommand/ExternalCommandExecutor.cs

Process process = new Process();
                process.StartInfo.FileName = executableLocation;
                process.StartInfo.UseShellExecute = false;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError = true;
                process.EnableRaisingEvents = true;
                process.OutputDataReceived += (object sender, DataReceivedEventArgs e) => {
                    if (!string.IsNullOrWhiteSpace(e.Data)) {
                        StatusUpdate(src, e.Data);
                        Logger.Info($"STDOUT: {e.Data}");
                    }
                };
                process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) => {
                    if (!string.IsNullOrWhiteSpace(e.Data)) {
                        StatusUpdate(src, e.Data);
                        Logger.Error($"STDERR: {e.Data}");
                    }
                };

It just captures STDOUT and STDERR and logs that with its internal logger.

It's worth checking if there is log output window or log file somewhere for NINA

Link to comment
Share on other sites

This suggests that changing "true" to "false" in this line:

"process.StartInfo.RedirectStandardOutput = true;"

would not redirect the command shell's output back to NINA?

EDIT: the side-effect might be a global effect on all called-processes though!

Edited by wulfrun
Link to comment
Share on other sites

6 minutes ago, wulfrun said:

This suggests that changing "true" to "false in this line:

"process.StartInfo.RedirectStandardOutput = true;"

would not redirect the command shell's output back to NINA?

EDIT: the side-effect might be a global effect on all called-processes though!

Yes, here is documentation for property:

https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.redirectstandardoutput?view=net-6.0

Quote

When a Process writes text to its standard stream, that text is typically displayed on the console. By setting RedirectStandardOutput to true to redirect the StandardOutput stream, you can manipulate or suppress the output of a process. For example, you can filter the text, format it differently, or write the output to both the console and a designated log file.

 

Link to comment
Share on other sites

Yes it gets logged to the standard log file:

2022-05-21T08:31:19.5234|INFO|SequenceItem.cs|Run|206|Starting Category: Utility, Item: ExternalScript, Script: "C:\Users\Martin\Desktop\NINA Astro Images-MelePC\test.bat"
2022-05-21T08:31:19.5234|INFO|ExternalCommandExecutor.cs|RunSequenceCompleteCommandTask|43|Running - C:\Users\Martin\Desktop\NINA Astro Images-MelePC\test.bat
2022-05-21T08:31:19.6892|INFO|ExternalCommandExecutor.cs|RunSequenceCompleteCommandTask|54|STDOUT: C:\Program Files\N.I.N.A. - Nighttime Imaging 'N' Astronomy>cls
2022-05-21T08:31:19.6902|INFO|ExternalCommandExecutor.cs|RunSequenceCompleteCommandTask|54|STDOUT: C:\Program Files\N.I.N.A. - Nighttime Imaging 'N' Astronomy>cd\
2022-05-21T08:31:19.6912|INFO|ExternalCommandExecutor.cs|RunSequenceCompleteCommandTask|54|STDOUT: C:\>cd\test
2022-05-21T08:31:19.6922|INFO|ExternalCommandExecutor.cs|RunSequenceCompleteCommandTask|54|STDOUT: C:\test>mkdir martin 
2022-05-21T08:31:19.6932|ERROR|ExternalCommandExecutor.cs|RunSequenceCompleteCommandTask|60|STDERR: A subdirectory or file martin already exists.
2022-05-21T08:31:19.6932|INFO|ExternalCommandExecutor.cs|RunSequenceCompleteCommandTask|54|STDOUT: C:\test>cd\test\martin
2022-05-21T08:31:19.6942|INFO|ExternalCommandExecutor.cs|RunSequenceCompleteCommandTask|54|STDOUT: C:\test\martin>dir *.* 
2022-05-21T08:31:19.6963|INFO|ExternalCommandExecutor.cs|RunSequenceCompleteCommandTask|54|STDOUT:  Volume in drive C has no label.
2022-05-21T08:31:19.6963|INFO|ExternalCommandExecutor.cs|RunSequenceCompleteCommandTask|54|STDOUT:  Volume Serial Number is 02CC-9995
2022-05-21T08:31:19.6963|INFO|ExternalCommandExecutor.cs|RunSequenceCompleteCommandTask|54|STDOUT:  Directory of C:\test\martin
2022-05-21T08:31:19.6972|INFO|ExternalCommandExecutor.cs|RunSequenceCompleteCommandTask|54|STDOUT: 20/05/2022  17:39    <DIR>          .
2022-05-21T08:31:19.6972|INFO|ExternalCommandExecutor.cs|RunSequenceCompleteCommandTask|54|STDOUT: 20/05/2022  17:39    <DIR>          ..
2022-05-21T08:31:19.6972|INFO|ExternalCommandExecutor.cs|RunSequenceCompleteCommandTask|54|STDOUT:                0 File(s)              0 bytes
2022-05-21T08:31:19.6972|INFO|ExternalCommandExecutor.cs|RunSequenceCompleteCommandTask|54|STDOUT:                2 Dir(s)  186,032,549,888 bytes free
2022-05-21T08:31:19.6982|INFO|ExternalCommandExecutor.cs|RunSequenceCompleteCommandTask|54|STDOUT: C:\test\martin>pause
2022-05-21T08:31:24.4668|INFO|ExternalCommandExecutor.cs|RunSequenceCompleteCommandTask|54|STDOUT: Press any key to continue . . . 
2022-05-21T08:31:24.4668|INFO|ExternalCommandExecutor.cs|RunSequenceCompleteCommandTask|54|STDOUT: C:\test\martin>echo press any key to continue 
2022-05-21T08:31:24.4668|INFO|ExternalCommandExecutor.cs|RunSequenceCompleteCommandTask|54|STDOUT: press any key to continue
2022-05-21T08:31:24.4678|INFO|ExternalCommandExecutor.cs|RunSequenceCompleteCommandTask|54|STDOUT: C:\test\martin>exit

Link to comment
Share on other sites

As I mentioned earlier I had written some VB code ( a few years ago) for an Excel utility which called windows command, but in my case I needed to hide the output so knew there were options when calling a Windows  execute. This is different from a user running the command in a console or invoking from file explorer etc.

I had an idea that could help, can you create 2 batch files. The first run by Nina calls the second which does the actions, I don;t have Nina so can't try a quick test myself.

Link to comment
Share on other sites

1 hour ago, StevieDvd said:

As I mentioned earlier I had written some VB code ( a few years ago) for an Excel utility which called windows command, but in my case I needed to hide the output so knew there were options when calling a Windows  execute. This is different from a user running the command in a console or invoking from file explorer etc.

I had an idea that could help, can you create 2 batch files. The first run by Nina calls the second which does the actions, I don;t have Nina so can't try a quick test myself.

Tried that and it made no difference

Should have added an unfortunately, sounded a bit abrupt otherwise 🙂

Edited by scotty38
  • Sad 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. By using this site, you agree to our Terms of Use.