Terminating input using Ctrl-D character not working [duplicate] - perl

This question already has answers here:
Ctrl+D doesn't stop application from executing in command window
(5 answers)
Closed 7 years ago.
I attempted to write a Perl script to take user input. I am
on Windows 8 and Cygwin.
When I try to run my code it expects user input as it should, but when I attempt to press Ctrl-D the program still tries to accept input instead of signalling the end of input.
Here is my code below. Why is this the case? Is there a way I can overcome this without switching away from Cygwin? I do not want to press Ctrl-Z or Ctrl-C as I don't want to stop the execution of the program.
#!/usr/bin/perl
while ( $line = <> ) {
print $line;
}

In Windows you have to use CTRL-Z instead of CTRL-D.

Related

Disable Ctrl key simulation by Win Key in AHK

I've got two AHK scripts running simultaneously.
First is:
#I::Run calc.exe
And second:
^I::Run notepad.exe
So, when I press Win + I to run first script, second script starting too, because WIN key simulates CTRL key. How to disable it? Without change keys.
Assuming that you are trying to open calculator with the first script and Notepad with the second, you forgot to put the Run command before calc.exe in the first script.
In other words, the reason that it appears that the first script does not function is not caused in any way by the second script, just change the code of the calculator script to:
#I::Run calc.exe

MATLAB return current values on interrupt [duplicate]

This question already has answers here:
In Matlab, is it possible to terminate a script, but save all its internal variables to workspace?
(3 answers)
Closed 7 years ago.
If I press Ctrl + C during the execution of a long loop, I lose all the work that has done so far. So is there a way in MATLAB that I can press Ctrl + C, but return the current variables?
so what I want as a pseudo-code :
for i=1:very_long
do_things();
if keypress(ctrlc_orsomeothercombo)
disp('Im bored!');
return;
end
end
Is this possible?
Thanks
If you turn stop on errors on, then interrupting it, even with ctrl+c, brings you to the place where it was executing and you have the whole workspace available:
dbstop if error

How to stop a Matlab script but don’t kill the process? [duplicate]

This question already has answers here:
Stop and continue execution from debugger possible?
(6 answers)
Closed 8 years ago.
Strg+C stops and kills a Matlab script (at least sometimes). But is there a way to stop a Matlab, take a look at some variables and continue the calculation?
I am not talking about just setting a breakpoint. I want my script, let’s say run for couple hours come back to it hit some buttons that stops the calculations take a look at some variable and then continue the calculation.
I tried to find out if there is some shortcut key for this – I am quite sure there isn’t.
Now I was thinking about including an if-case that looks if a certain button was pressed by the user. If so there would be a useless k=0 line and a breakpoint on it. And if no one is pressing this button the loop would continue. But this is where my limited Matlab knowledge leaves me. I don’t know if there is a way to ask for a user-button press but don’t wait for a button press like in the function input. Also I just have a running script, I don’t have any GUI.
To drop to the command prompt you need the command keyboard and then type return when you have finished (you don't need a breakpoint). The tricky bit is how to trigger it. There a few options. The easiest is to open a figure window. The following code halts the process when any key is pressed.
keyDownListener=#(src,event) keyboard;
fig = figure;
drawnow
set(fig,'KeyPressFcn',keyDownListener)
for p=1:10000
%do some thing
end
You can modify this to test for a specific key since the keypress is contained within the event struct.
To use no figure gui at all its more of a problem. I'm not aware of a non blocking keyboard input method. A mex file the runs kbhit() in C might do it, but kbhit() is not standard C so it would only work on Windows. An easier option maybe to test for the presence of a file.
for p=1:100000
if exist(fullfile(pwd,'halt.tmp'),'file')
keyboard
end
%do something here
end
This drops to the debug console when halt.tmp is created in the current directory.
Other potential methods could involve using multiple threads to read 'input' (either the Parallel computer toolbox or undocumented Java code), or using http://psychtoolbox.org/ as mentioned by #bdecaf

Autohotkey - Repetitive hotkey [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
how to send a letter as itself when it is used as hotkey in autohotkey
When I try to run the script:
v::Send tv
it starts typing t repetitively.
And while playing with autohotkey I probably did something wrong and now it quits saying
Error at line 1.
Line Text: ; v::Send tv
Error : Invalid hotkey.
The program will exit.
(I made it a comment using ; later, the problem persisted before that.)
Can someone tell me what I am doing wrong?
The hotkey is triggering itself when it sends a v. Try using $:
$v::Send tv
I'm not sure what caused it to say "Invalid hotkey".
Alternatively you can use:
:?*:v::tv ; * = no need to press enter, ? = will execute vene if letters have been typed before.
To avoid problems of not being able to use the letter v anywhere else, I normally use v\ this combination because it is easy and unique:
:?*:v\::tv
And if you want to limit the behaviour of the v key to just one application, I would use the AutoHotKey spy to get the application specific ID or name and place the hotkey inside an #ifwinactive. You will need to put SetTitleMatchMode, 2 at the top of your script. This sets the string mathing behaviour for functions like #ifwinactive. In this example v\ only works in Google Chrome.
SetTitleMatchMode, 2
#ifWinActive, Chrome ; limits the use of the following hotkey(s) to Chrome only.
:?*:v\::tv
#ifWinActive

Perl running cmd with backspace

When I run an application (wget.exe) using cmd, the output contains backspace characters that make the output display nicely. But when I run it in perl using open or backstick with 2>&1, it prints out the output in a different way that doesn't use backspace. How can I still keep the backspace display?