Alert on operation completion in windows cmd - windows

Using windows cmd I have to put large programs on compilation which take large amount of time. Everytime to know whether operation is complete or not I have to check cmd again and again. I want to know whether there is way by which I can make changes to cmd such that it gives me a signal that operation has been completed by playing sound or by opening a dialog etc.
Please share if anyone has some idea

There can be many ways to achieve this
This is the easiest
While your code is compiling (ie compiling has just began) in the same cmd prompt
type " ctrl + G " and press enter this will go to the input stream of cmd and will wait there until it can be executed , ctrl +G is the BEL character which gives you a single beep when you execute it .
You can also enter multiple BEL characters to get multiple beeps upon completion of the task.
A harder way could be , to write a python script that executes the compilation command say "g++ my_prog.cpp" and upon completion plays a sound or give you a simple popup notification via a windows message box.

Include in yout batch file
msg console /time:3600 "The task has ended"
Send a message to the console and keep it open (if not closed by the user) 3600 seconds (if not indicated there is a 60 seconds timeout).

Related

LabVIEW: how to control two events one after the other from one button

I am working on a project where I have to send arguments by a command line to a python file (using system exec) and then visualize the results saved in a folder after the python file finishes executing. I need to have this by only clicking on one button, so my question is, if there is any way to realize this scenario or maybe if I can order the events.
Now I have included the flat sequence structure to the block Diagram so I can order the events, but I had an issue with making the program (the python file) running every time I press the Test button (it only runs in the first time I click on the Test button), I tried to use the while loop but I couldn't execute it again unless I restart the program.
The way you phrased your question makes me think that you want to wait until the command you call via system exec finished and then run some code. You could simply use a sequence structure for this.
However, if you need to do this asynchronously, i.e. launch the command and get an event when the command finished so you can draw the results, you will need to resort to asynchronous techniques like "Start Asynchronous Call" and "Wait On Asynchronous Call", or for example queues and a separate code area for the background-work.
Use "wait until completion?" input of System Exec function to make sure the script finished execution, then proceed with the results visualization part.

Powershell Script is slow in opening an application

I have a PowerShell script that opens a file when you press a hotkey like: ctrl + alt + f so that the app automatically runs every time the user presses those key combinations.
Now, the problem is that it indeed opens the application/file, but it takes 4-5 second to process it. I want the process to be fast enough so that the script opens the desired files the moment the user presses the key combinations and not seconds after it. I don't know what caused this slowdown...
Here's the script:
# Get the Desktop dir. path.
$desktopDir = [Environment]::GetFolderPath('Desktop')
# Create the shortcut object, initially in-memory only.
$shc =
(New-Object -ComObject 'Wscript.Shell').CreateShortcut("$desktopDir\linkthis.lnk")
# Set the target executable (name will do if in $env:PATH).
$shc.TargetPath = 'C:\Users\abhay\Downloads\Test\script.py'
# Assign the hotkey.
$shc.Hotkey = 'Ctrl+Alt+F'
$shc.Save()
(Code originally taken from this question asked by me earlier)
Edit1:
It isn't just the case with my .py script. It's the same when opening even notepad too! And the script indeed runs fast when I boot up my PC but after some time (2-3min) it causes the delay in opening again. I Just can't figure it out why...
I don't know why it runs fast at the first 1-2 min and then slows down
(Also, running the files manually is quick. It's just slow with the script)
Edit 2
Hey guys, I just discovered that it's just the case with my computer. It's working fine on my dad's PC with pentium processor 🥲 but I still appreciate any fix for my system if possible. Thanks. May god bless you and my father. Things are really wrong with me these days...

VBScript onTimeout then function

I have a VBScript I am working on that uses another object.
Sometimes that Object will get stuck. My VBScript code will hang on that line until it's "done". When it times out, I want to send the .Close command to the Object before the VBScript closes.
How can I tell when my VBScript times out?
I know that I can put WScript.Timeout = 60
Maybe something like..
WScript.Timeout = 5
do while true
loop
sub WScript_timeout()
msgbox("OK")
end sub
By setting the Timeout property you instruct the interpreter to automatically terminate the script when the timer expires. This is the same as running the interpreter with the option //T:xx and can't be caught/handled from within the script. What you want requires the ability to run code asynchronously, and VBScript doesn't really support that.
The real answer (to the question "How can I tell when my VBScript times out?") is that you can't. In common with almost all scripts, if VBScript stops running (because it's timed-out) the running thread ceases to run, so it can't report its status.
But there is a solution. However, it requires some cunning.
If you run a batch script instead, wherever you use that script to launch a new batch script (e.g. batch_1.bat includes this line: CALL batch_2.bat), the 2nd script will run, but the 1st script will wait.
Processing of the 1st script sits and waits (at the CALL) until script 2 stops running: at that point, control is returned to script 1, which continues with any code following the CALL, code which might be used to report the fact that script 2 has ended -
CALL batch_2.bat
ECHO The batch_2.bat script has stopped running && cmd /k
There are ways of launching batch_2.bat without causing batch_1.bat to pause until the 2nd script has finished, but they are not relevent here.
Theoretically, a batch script doesn't support parallel processing. VBScript certainly doesn't either. But the foregoing technique shows one method whereby parallel processing can be achieved, after a fashion, in a batch script -- which makes it one-up on vbScript!
.
One way to be certain that vbScript will time out, if the script hangs, so that the script must either complete successfully or fail (so you are never left with a frozen script due to it "hanging"), is to use a WScript function in your .vbs file and set the Windows Script Host settings to time out after (say) 30 seconds -
A. Open the "Windows Script Host Settings" dialog box:
Go to: Start > Run
In the "Open" box, type: WSCRIPT
Click "OK".
B. Set a timeout, to occur whenever WSH runs:
Select the option: "Stop script after specified
number of seconds".
In the "seconds" box, type the time limit to be
applied to all scripts (default is 10 seconds).
.
Here's a function to find and show what the current WSH/WScript timeout setting is (and if it shows that this setting hasn't been set yet, set it) -
WScript.Echo("WSH timeout: " + WScript.Timeout);
.
The option //T:xx can't be used, because it's a CScript function, which doesn't work in WScript, so can't be used in a .vbs vbScript file.
.

2-way communication with background process (I/O)

I have a program that runs in the command line (i.e. $ run program starts up a prompt) that runs mathematical calculations. It has it's own prompt that takes in text input and responds back through standard-out/error (or creates a separate x-window if needed, but this can be disabled). Sometimes I would like to send it small input, and other times I send in a large text file filled with a series of input on each line. This program takes a lot of resources and also has a large startup time, so it would be best to only have one instance of it running at a time. I could keep open the program-prompt and supply the input this way, or I can send the process with an exit command (to leave prompt) which just prints the output. The problem with sending the request with an exit command is that the program must startup each time (slow ...). Furthermore, the output of this program is sometimes cryptic and it would be helpful to filter the output in some way (eg. simplify output, apply ANSI colors, etc).
This all makes me want to put some 2-way IO filter (or is that "pipe"? or "wrapper"?) around the program so that the program can run in the background as single process. I would then communicate with it without having to restart. I would also like to have this all while filtering the output to be more user friendly. I have been looking all over for ideas and I am stumped at how to accomplish this in some simple shell accessible manor.
Some things I have tried were redirecting stdin and stdout to files, but the program hangs (doesn't quit) and only reads the file once making me unable to continue communication. I think this was because the prompt is waiting for some user input after the EOF. I thought that this could be setup as a local server, but I am uncertain how to begin accomplishing that.
I would love to find some simple way to accomplish this. Additionally, if you can think of a way to perform this, do you think there is a way to also allow for attaching or detaching to the prompt by request? Any help and ideas would be greatly appreciated.
You could create two named pipes (man mkfifo) and redirect input and output:
myprog < fifoin > fifoout
Then you could open new terminal windows and do this in one:
cat > fifoin
And this in the other:
cat < fifoout
(Or use tee to save the input/output as well.)
To dump a large input file into the program, use:
cat myfile > fifoin

powershell bash loops are randomly stuck waiting for keyboard input

I have bash script I am running from powershell in windows that does a for loop. Every once in a while, one of the loop iteration hangs until I hit enter on the keyboard.
This doesn't happen all the time, in fact, it happens pretty rarely, but it still does.
The interesting thing is that my loop innards is basically time _command_ and so after I hit enter, it'll tell me how long the command took to run. The command actually takes way less time to execute than the loop iteration takes - because it's waiting for keyboard input for some odd reason.
It's pretty annoying to leave a script running overnight and come back in the morning to see that it didn't get very far.
Does someone knows WHY this happens and WHAT to do to get around it?
Thanks,
jbu
I have encountered the same problem several times. Now I guess I have found the reason!
If you ever press the mouse within the powershell, it might get stuck and need user to press "enter" to continue. So the get-around-way is to make sure that you didn't accidentally press your mouse within the shell window while you are already running some program...
Goto the powershell properties and unselect 'Quick Edit'/'Insert' check boxes. If these are selected, the console pauses output and resumes only when an Enter key is pressed ( You can identify this by monitoring the console title bar- it will switch from "Administrator:Windows PowerShell" to "Select Administrator:Windows Powershell"
Until you post the script, there's little we can do to help.
However, in general, one of your commands probably returns a null once in a while as input to stdin of another command which, upon seeing null looks to the terminal as stdin. Or something along those lines.

Resources