I recorded a certain process by autohotkey and saved as auto.ahk in Windows system. I need to run that from Linux system, so I created a bat file with content start 'd:\auto.ahk' and saved as test.bat. But when I use the following code in terminal, it doesn't work
ssh user#192.00.00.00 'd:/test'
Because of the fact that you .ahk script requires the actual autohotkey program on windows to run (it's the interpreter between raw text and binary commands to windows), what you're likely running into is that the bat file is trying to just "run" your .ahk script, but can't run a raw text file like a program. What you may be able to do to fix this is compiling your .ahk script, making it an executable. Then, you could call the executable directly, just like you would any other .exe on the computer. (you might also want to try starting any other .exe this way like notepad to make sure your method of running the program is correct)
Another solution would be, as #Matthew Strawbridge suggested, to have a script running quietly in the background of the computer, periodically checking the contents of a file that the .bat can write to. This has the added bonus of you being able to customize what the script does by what is written in the check up file.
Related
I am making a small-scale project which reads from a file of 101 items, creates a vector of strings, and then randomly accesses one of the items and prints it to the standard output. The program works exactly as intended when run from the terminal, whether through cargo run
or by running the executable from the terminal with ./executable_name. The problem is, if I double click on the executable without a terminal open there is nowhere for the information to be printed and the program is essentially useless. I know how to check if a terminal is open using
if atty::is(Stream::Stdout) {
println!("Already in terminal");
} else {
// this is where I get confused
}
but from there I don't know where to go. I have experimented with things like Command::new("sh"); but am struggling with the documentation. Eventually, the idea is that I can compile this on my partners Mac without losing its functionality as I am writing it on Linux, and create an easy to use application to run it on her machine.
Programs generally do not open their own terminal windows. The way you arrange for one to exist varies by platform:
On macOS, you actually don't have to do anything; the default behavior of double-clicking an executable is to open a terminal to run it in. (GUI applications have their executables inside of .app packages, so that this behavior does not apply to them.)
On Windows, whether a terminal is opened is a property of the executable, which you can set in Rust with the windows_subsystem attribute. However, the default value is console so you don't need to do anything. (I've heard it is also possible to open a console window after startup, but I am not a Windows developer and can't advise you on the proper system calls to do that.)
On Linux, you'd create a .desktop file that specifies Terminal=true, to ask the desktop environment to launch your program in a terminal, and double-click that file rather than the executable. Or, you could make your program launch a terminal emulator and instruct it to start your program again within itself, but how you do that will depend on what terminal emulator programs are installed.
The one thing you'll have to do for all these cases is add a “Press Enter to exit” prompt to your program. Otherwise, the terminal will close immediately after your program exits, and so your output won't be visible.
eprintln!("Press Enter to exit.");
std::io::stdin().read_line(&mut String::new()).unwrap();
I use Windows 10 and an .exe program (in-house code written by a colleague) that imports data from .txt files. Since 99% of my use of .txt files are for this program, I've changed the default Windows program so that this .exe file is run automatically when opening a .txt file. If I need to access the .txt file directly, or use it for another purpose, I right-click and choose "edit."
I'm now writing a program of my own (using Octave 4.4.1), which also uses .txt files that sometimes need to be opened/edited, but if I use "open(filename)" in my Octave script, of course it just opens the .exe file. I can open the .txt file from there, but I'd like to skip this middle step, since the aforementioned .exe program is not intended to be used in this process, and there are other users of my code that don't have the .exe program installed.
Is there a way to duplicate the right-click/edit feature in Windows within Octave code? "edit(filename)" opens the file in the native Octave editor, which is technically viable, but not exactly a desirable scenario. I've also tried changing the default Octave editor to Notepad, and I've tried Notepad++ as well, but I have had absolutely no luck, even with significant effort, of making Octave use an external default editor of any kind (even when I remove the .exe program as the default for .txt files). Thanks in advance for any advice you can offer.
You can send command-line commands from Octave using the system() function.
For example, to open the file in notepad, you could do
[status, output] = system("notepad <path_to_text_file>.txt");
If notepad isn't in your system path, you will have to add it to or use the full path to the notepad executable
Or, if you want to use Notepad++, add it to your system path and then do
[status, output] = system("notepad++ <path_to_text_file>.txt");
I need to make my Autohotkey scripts run at startup, so I think the best way is to save the file .exe in the startup folder, but the .exe file is saved automatically in the same folder of the source, so save the source in the startup folder could be a solution too, but it also opens the source at startup.
Now I'm using the syntax highlight plugin for autohotkey in SublimeText3, but I don't know if there are some way to save the .exe file to a different folder than the one where the source (I'm a noob in informatic).
I'd tried using SetWorkingDir in the Autohotkey script and costumizing the AutoHotkey.sublime-build file using working_dir, but I don't know how they work, so I didn't achieve the goal.
I need a way to edit .ahk with Sublimetext3, keeping my scripts in "documents" and, when I build, save the exe in another folder.
If you're just looking to have your AHK files load when you start up Windows, then the Startup folder is indeed the right location. An elegant solution would be to call the other scripts from this main script.
Since the default AutoHotkey.ahk script is contained in your Documents folder, you can include or run various other AHK scripts, depending on whether you want them to run under one AutoHotkey instance, as one per script, or some combination of the two.
Documentation on Include is fairly solid. The example from the linked page:
#Include C:\My Documents\Scripts\Utility Subroutines.ahk
#Include %A_ScriptDir% ; Changes the working directory for subsequent #Includes and FileInstalls.
#Include C:\My Scripts ; Same as above but for an explicitly named directory.
Similarly, you can Run like below:
Run, C:\My Documents\Scripts\Utility Subroutines.ahk
I am not sure I understood well your question. (Maybe you could make it clearer)
To run an .ahk at startup you can save it in your startup folder and you need simply to associate .ahk with the AutoHotkey.exe. (Always open with AutoHotkey.exe). You don't have to have the 2 files in the same location.
You could also add a shortcut to your .ahk file to your startup folder.
If you have many scripts copy each shortcuts to the startup folder.
I know I can use ResHacker to change a resource from windows and I know I can use ResourceUpdate function to do the same problematically (again in windows). My problem is that I have to update the icon of a windows exe file in linux, without using wine.
(the reason for not using wine is that this process should run on an automation server that change the files and sign them).
I don't know even where to start from.
You can change a files metadata like this:
gvfs-set-attribute '/path/to/file' -t stringv metadata::custom-icon "/path/to/image.png"
There's a program called windres that should suit your needs
Whoops, that's just a resource compiler, sorry.
However there is pefile a python module for working with PE executables, perhaps you could write a script with it that does what you want
I am trying to open a downloaded .exe file but it closes as soon as it opens. Is there any possible way so that I can open it for a longer duration to read the content.
It's probably a console application rather than a GUI application. Use the command prompt to run the .exe.
Do the following...
Hold down your Windows key on your keyboard and then tap "R".
This will bring up the Run dialog. Type in "cmd" (without the quotes). Hit enter.
(this will work in all Windows versions - browsing the start menu/screen differs in each version)
If you saved the file to c:\downloads and it's called myFile.exe, type
C:
cd C:\Downloads
myFile.exe
Some of the steps are a bit redundant - if you know what you're doing in the command prompt then skip as needed (but then you probably wouldn't be posting this question). This will work even if you saved the file to D:\downloads.
Another example - if you saved the file to D:\folderA\Folder with a space\ and the file is called "my file with a space.exe" then type
D:
cd "D:\folderA\Folder with a space"
"my file with a space.exe"
If there is an issue (eg it's a 64-bit executable and you're on 32-bit Windows) then you may get a better error message at the command line.
There are so many reasons why the executable does not run. Here are some ways to check what is going wrong:
Is it your .exe? Do you known the "normal" behavior?
When you download it manually, it the result the same?
Do you download the .exe manually or via your application?
Do you see any problem in your Windows Event Viewer?
Is it the same result if you try to download the .exe via different browsers (IE, FF, ...)?
More details are welcome!
The nuget.exe file is not a console GUI application but rather a console package. Once you've downloaded it, you'll want to place it in a folder outside your Downloads folder. For example, C:\NuGet\nuget.exe - then set it as a PATH variable so that it's executable from anywhere.