My computer has a different problem.
Whatever the batch file i run, it won't starts its execution until i press any key from keyboard until that it holds the data without printing on console/command prompt.
once i press a key the execution starts.
Again somewhere else it does the same thing then i need to repeat the same.
My Operating System is Windows 7 Ultimate 64 bit.
I looked in the internet for solution. but strangely it seems like no one got this problem.
Can anyone please provide me a solution for this?
Related
So, I've written a C executable on Linux for Windows using mingw32-gcc. It is a basic Input-Output program, you type an input and get an answer.
Problem is the cmd shuts down immediately, so the user can't see the output.
Assuming I cannot use Windows to edit the executable there, what should I change in my code/ what flags should I use when compiling it?
inb4:
the user is supposed to click and run it, so running it from cmd won't help.
adding getchar()/scanf() at the end of my code doesn't work, and it feels a bit like cheating.
SOLVED: so all I had to do was to actually add a getchar() after every scanf() and one more at the end of the code for the user input to close the cmd.
Waiting for input at the end is not cheating, but common practice. How else should program know for how long it should stay opened? Closing program by closing console window directly is more cheating than waiting for user input to finish.
You can for example prompt user to hit any key like Press any key to exit... or something similar.
If you want some specific delay, you can use Sleep() from windows.h instead of waiting for input.
See https://stackoverflow.com/a/3379146/3035795
I'd like to do something similar to Removing PDF password protection, knowing the password but in Windows. I have a folder with several PDFs that all have the same password, which I know. I would like to remove the password and overwrite the original files (don't worry, my data is a copy of another folder).
My thoughts are to use Autohotkey and create a script to open the file, paste the password, click enter, press Ctrl+P, click Print as PDF, save as the original file name, close Edge (which is what I'm using to open the PDFs), and then go to the next file in the folder.
I'm honestly not that familiar with AHK and would appreciate any help in what the code should be.
Thanks!
Edit: Here's some code I've tried but it doesn't seem to work.
^+q::
Loop %A_WorkingDir%\*.pdf
sleep 10000
Send, PASSWORD
sleep 2000
Send, {Enter}
Send, ^p
Click 105,694
WinClose, A
Return
When looping through files (using a files-loop as you have), it's not actually opening these but is giving you access to its OS-level properties, such as path, name, and system properties. You can use this information to open each one, using Run - something like, Run , %A_LoopFileLongPath%. Note that you may need to set Edge as your default PDF viewer if it isn't already.
Currently, your loop is only executing the line just beneath it, which is a 10-sec. sleep. You have 2,000 PDFs? That's about 5.5 hours of sleep before moving on. ;) If you want to execute more than one line, enclose it in braces { }, like so:
Loop , 1000
{
; stuff
}
From there, I would consider using WinWaitActive along with possibly ControlSend instead of Sleep and possibly Send. This will make your script more robust and may also take less time (assuming 10s is an upper bound). If at all possible, I would also discourage using clicks as these can sometimes be problematic (sometimes you have to send it multiple times for one click or locations might change). You can definitely make it work without these suggestions, it just might take more trial-and-error.
It may also be a good idea to build in a way to pause your script if needed, since this will likely take some time to do things to 2,000 files.
The help documentation is excellent and shows proper syntax and examples. I'd recommend consulting it for each of the commands.
https://www.autohotkey.com/docs/AutoHotkey.htm
I have a problem with a project in Visual Studio. The project is created as an empty project, and then a .c file was added. The problem is that the console closes immediately after the program ends when I redirect input to a file.
I tried going to Properties > Linker > System and selecting /SUBSYSTEM:CONSOLE option, but it doesn't solve this. This always worked for me, but now when I redirected the input, the console closes right after the program execution and I can't see the output.
I redirected the output by adding <"in.txt" in Configuration properties > Debugger > Command, and it works exactly the way I wanted, except the console closes too soon. This problem doesn't occur when I redirect the output.
Also using getchar(), scanf(...) or system("pause") didn't work.
I would love to solve this by only changing some project settings and without adding some extra code to a program if possible, but any solution is appreciated.
Edit: As I stated above, I have tried several things, including some answers from similar questions, but none of them helped.
It's standard windows behavior that a console program automatically gets a new console window when not started from an existing one and this new window is automatically closed as soon as the program ends. So the key to force the window to stay open from withing your program is to prevent program termination.
With things like getchar(), you rely on the fact that these calls block until more input is available. This works fine as long as input actually comes from the console. But when you redirect input to come from a file, there will always be input available -- either there's more to read from the file or you'll instantly get an error (e.g. for EOF). That's the reason all these "tricks" don't work any more.
A simple and very unclean version is to just add an empty loop to the end of your program, so it never exits. On the windows platform, this could be something like
for (;;) Sleep(1000);
The call to Sleep() (include windows.h to use it) makes sure this loop doesn't burn CPU cycles. You'll have to forcefully end your program by hitting Ctrl+C or closing the window. Of course, don't leave this loop in your final program, it would be quite annoying when started from an existing console window.
There might be better solutions to this problem, but I hope I could explain you why this is happening.
Sorry, this might be a simple question, but I can't find a solution to that. I have a console application, which has several parameters. I show a usage information, how to use the application correctly, but since I have to explain each parameter it is very long. The whole usage won't fit in the console window.
So how can I display only that much from the usage which fits to actual window size?
A good example is cmd. If you open a command prompt, and then type cmd /? the usage information will be shown, but it will only show that much of the usage which will fit to the actual window size, and then waits for a keypress. If the window is small, you have to press a key 7 times. But if you make the console window bigger you have to press a key less.
So my question, how can I achieve this?
I don't know how you would execute it, but what you need is a pager.
I haven't tested it, but here it says the more command is available in MS-DOS and most Windows versions (Windows 95, 98, ME, NT, 2000, XP, Vista, 7 & 8).
If you were running it standalone, you'd do echo some-long-text | more. I don't know how you'd use this from your own program, but that should be the way (I imagine there should be something like POSIX's system() syscall to run a command).
I think this is simple, but not for me obviously!
I have a console-application. I need to read input from the keyboard, but stdin has been redirected to a file. So how do I create a FILE-Handle that points at the keyboard-stream which i can use with fgets etc.?
I found out that ttyname(0) seems to be what i look for in a POSIX-environment, which I don't have here. I'm in a Windows-system with standard Visual Studio compiler.
Any ideas? Thank you in advance.
There's no easy/portable way to tell if a keyboard exists (your application may be being run from a terminal emulator from a serial port, a telnet session or anything else). If a keyboard actually does exist (including a picture of a keyboard on a touch screen), then you can't really tell how many layers of software the keystrokes need to pass through before they get to your application (e.g. keystrokes might go from a keyboard driver to an input method editor to a GUI to a shell to your application). This means that attempting to get keystrokes directly from a keyboard driver or something is a bad idea that will fail in almost all cases.
The best way to solve your problem is to find out which series of design failures led to STDIN being redirected in the first place.
For example; maybe the application should've had a command line option to read some data from a file; so that the application can get some data from the file and some from STDIN (and get all data from STDIN if the command line option isn't present).
Pulling from the dim dark days of DOS programming here: try opening "CON:" (Console), a reserved word. Hopefully it will open the same way in Windows. The colon may or may not be required. Both "dir >con:" and "dir >con" still work in command prompt.
Also, be sure to use something from the setbuf() family on the output handle to avoid buffering... it's not supposed to buffer terminal I/O, but it never hurts to be sure.
Again, not sure, but I suspect opening separate FILE *conin, *conout for output and one for input may help if you seem to have troubles with one handle doing both input and output.