How do you run programs in Windows terminal? - windows

What is the windows equivalent to "./filename"
So for example I would usually compile by doing something like:
gcc -c homework1.c
gcc -o homework1 homework1.o
This would give me the executable names homework1
And for me to run the program, I would type: ( ./homework1 ) <-- ignore the parenthesis.
Usually I was write all my code in my schools Unix Shell thingy and I also compile it and run it there, but recently I think I took up all the disc space (because it says "disc quota exceeded").

Run cmd.exe
Go to where the program is example : cd C:\foder1\
Then type the program name with extension, for example : test1.exe or "test1.exe"

In windows (as in Linux) you can either run a program though a GUI interface or from a shell environment.
The GUI option is a program called Explorer, you navigate through the file system and double click executable files to run then. Executable typically have the extension '.exe' or '.bat', but there are others.
The shell environment in windows is called the 'command prompt', you can run it by going to the start menu and selecting 'run' or simply press the windows key and 'r' simultaneously. A box will popup, type 'cmd' (without the quotes) and hit enter - the command prompt should open. From there you can navigate the file system using commands like 'cd'. To run your executable type the name of the file (it should work with or without the '.exe').
A nice shortcut to open the command prompt already at a particular path, is to browse to the folder in Explorer, hold shift and then right-click the folder - the resulting context menu that pops up should have an option like 'open in command prompt'.

Related

How do I run nvidia-smi on Windows?

nvidia-smi executed in a Command Prompt (CMD) in Windows returns the following error
C:\Users>nvidia-smi
'nvidia-smi' is not recognized as an internal or external command,
operable program or batch file.
Where is it located? CUDA is installed already.
Nvidia-SMI is stored by default in the following location
C:\Windows\System32\DriverStore\FileRepository\nvdm*\nvidia-smi.exe
Where nvdm* is a directory that starts with nvdm and has an unknown number of characters after it.
Note: Older installs may have it in C:\Program Files\NVIDIA Corporation\NVSMI
You can move to that directory and then run nvidia-smi from there. However, the command prompt window will not persist, making it very difficult to see the information. Additionally it is challenging to determine what the nvdm* directory is as this changes and there are multiple directories of this format. To complicate matters, unlike linux, it can't be executed by the command line in a different path. It's better to find the exact location and create a shortcut that runs it in a periodic manner.
To find your exact location
Open File Explorer (File Folder Icon on your Task Bar, Near Start / Cortana / Task View buttons).
In the left Pane, click 'This PC'.
In the main viewer, just to the top of the Icons, is a search bar. Type nvidia-smi.exe and hit enter. It will come up after some time.
Right-click and choose 'Open File Location' and continue with the below instructions to make a desktop shortcut, or double click to run once (not recommended, as it runs and closes the window once complete, making it hard to see the information).
Make a shortcut that runs nvidia-smi and refreshes periodically
Follow the above steps under 'To find your exact location'.
Right click on nvidia-smi.exe (it may just say nvidia-smi in the viewpane) and choose create a shortcut. It will likely tell you that you can't create a shortcut here, and ask if you want to put it on your desktop. Hit yes.
Now, on the desktop, right click on the shortcut you have just created, hit properties, and Under Shortcut > Target modify the string path to include -l < time you want it to refresh >.
For example, modify:
C:\Windows\System32\DriverStore\FileRepository\nvdm*\nvidia-smi.exe
to
C:\Windows\System32\DriverStore\FileRepository\nvdm*\nvidia-smi.exe -l 5
Then hit "Apply", and then "OK".
In this example, when you open the shortcut, it will keep the command prompt open and allow you to watch your work as nvidia-smi refreshes every five seconds.
You can add "C:\Program Files\NVIDIA Corporation\NVSMI" to PATH and than restart console.
System Properties > Advanced > Environment Variables > System Variables -> Path -> Edit > New > insert folder path with nvidia-smi
On my Windows 10 machine installed with CUDA 10.2, nvidia-smi.exe can be found at C:\Windows\System32.
Because C:\Windows\System32 is already in the windows PATH, running nvidia-smi in command prompt should now work out of the box
Go to the file explore then go to the C drive in the search bar type nvidia-smi
Wait sometimes when exe file is open right click go to the properties copy the location path
Then go to the anaconda command prompt change the working directory by using the copy path in step 2
Then write "nvidia-smi" hit enter
Click Here for more information
On Windows, you can use the Power Shell and type nvidia-smi -l 1 to GPU summary every 1 second, or nvidia-smi -lms every millisecond. Don't forget to add the CUDA environment files to PATH, as mentioned in the above suggestions.
You can try to write a .bat file for a one-click operation later.
ECHO Open folder
::my nvidia-smi folder (nvidia-smi.exe can be found on two different folders, either is ok)
cd /d c:\Program Files\NVIDIA Corporation\NVSMI
::cd /d c:\Windows\System32\DriverStore\FileRepository\nvami.inf_amd64_42b7e5f6a9e28f81
ECHO NVIDIA-SMI
::use `-l < time you want it to refresh >` to keep window
call nvidia-smi.exe -l 3
reference to #Hewston, the aforementioned script can be further simplified as follows:
::ECHO Open folder
::add my nvidia-smi folder to PATH variable
::cd /d c:\Program Files\NVIDIA Corporation\NVSMI
ECHO NVIDIA-SMI
::use `-l < time you want it to refresh >` to keep window
call nvidia-smi.exe -l 5

how to configure emacs to start in a directory (windows)

I am running emacs 25.1 under Windows. It is a standalone binary, not running under cygwin
I have a .emacs file that works on both windows and linux. On Windows, however, the command:
(cd "c:/Users/xxx/git")
does not start emacs in that directory. The command works, because if I evaluate the buffer, it does go to that directory. It is as though something else is executing AFTER my script causing emacs to default to the stupid windows default, wherever the code is.
Any workaround to make emacs start in my desired directory?
Create a Windows shortcut to the Emacs executable, and use that to start Emacs. Create the shortcut by right-clicking the file runemacs.exe in folder bin and choosing Create shortcut.
Then fill out the Properties in the Shortcut tab:
Field Target has the command for starting Emacs: the location and name of the binary (executable) followed by whatever options you want and any file or directory that you want to start editing.
Field Start in has the directory that I want Emacs to start in.
For example:
Target: D:\Emacs-25.1\bin\runemacs.exe --debug-init "d:\usr\some-user-name\some-directory"
Start in: d:\usr\some-user-name\some-directory
Then just double-click your shortcut to start Emacs. Or single-click it, if you pin it to the Task Bar.
You can create as many such shortcuts as you want, either to the same Emacs executable (e.g. with different options or startup directories) or to different executables (e.g. different Emacs releases).
Try using emacs-startup-hook, which runs after processing the commandline and init.el.
(defun jpk/emacs-startup-hook ()
(cd "/some/path"))
(add-hook 'emacs-startup-hook #'jpk/emacs-startup-hook)
If that doesn't work, some package is setting the CWD, and you'll have to track it down.

Executing a command-line .exe file

I have a .exe file converted from a .jar.
It is a command based application, so I have to start it with a batch script. Here is the batch script:
#echo off
cd C:\desktop\plant-text-adventure-win
start planttextadventure
pause
When I double click on the batch script, this happens: Windows could not find 'planttextadventure'. Please confirm if you have input the correct name and retry.
I don't know what is happening, I have no idea about cmd as I use Mac, but I can confirm I have an executable called planttextadventure.exe in a folder called plant-text-adventure-win.
You should test your batch file by executing it within a shell.
Simply enter within the start menu the command cmd to open up a shell. Within this black box you could now simply enter the commands from your batch script and lookout for some error message.
If you look at your script I would guess that the cd command (to change the current directory) is not correct. Maybe you should replace it with
cd %USERPROFILE%\Desktop\plant-text-adventure-win
because the desktop folder is on a default installation not directly under the root drive but within the user profile available.
Another solution to get this thing to work, is by opening the windows explorer, going to the .exe file you wish to execute and drag & drop the .exe file with a right mouse click onto the desktop.
Then a context menu appears and you select the option Create shortcut here.

Running raco on the Windows command line

I am trying to make a stand-alone Racket executable on the Windows platform. How do I go about running raco from the windows command line? I'm not familiar with it.
If I use the documentation and enter the following command into cmd.exe:
raco exe --gui main.rkt
cmd.exe tells me:
'raco' is not recognized as an internal or external command, operable program or batch file.
Substituting in raco.exe tells me the same thing.
I also tried typing:
'C:\Program Files\Racket\raco.exe' exe --gui .\main.rkt
into powershell and it gave me an Unexpected token 'exe' in expression or statement error.
For the first problem: you need to add to windows' %PATH% (an environment variable) the path to the executable. For the second problem: check the correct syntax for the exe command, and/or the "--gui" modifier, they're being misused. For instance, try this after solving the first problem:
$ raco.exe exe main.rkt
The above will create an executable main.exe file.
Download and install Racket, which includes DrRacket. (Of course, you’re welcome to use your preferred text editor, but the tutorials will assume you’re using DrRacket.)
Update the PATH envi­ron­ment vari­able on your system to include the direc­tory that holds the racket appli­ca­tion. On Mac OS and Linux, this path will be some­thing like "/path/to/racket/bin". On Windows, it’ll be some­thing like "C:\Program Files\Racket". Then, from the terminal, you’ll be able to run racket and raco (see raco: Racket Command-Line Tools).
Windows users who haven’t altered your PATH before: don’t panic. To add the Racket command-line programs to your Windows 10 PATH, click the Windows search box, type the word path, and then click on Edit the system environment variables. Click on the Environment Variables button. In the top window, which contains your user variables, find Path and double-click it to open. Click the New button and either use the Browse button to select your Racket directory, or manually enter its path. Restart your Windows terminal (either the Command Prompt or PowerShell) and now racket and raco should work.

How do I make my Perl scripts act like normal programs on Windows?

I want my Perl scripts to behave just like any other executable (*.exe file).
When I double-click on myscript.pl I want it to execute instead of opening in a text editor.
I want to run myscript.pl instead of perl myscript.pl.
I really want to run myscript instead of myscript.pl.
I want to run program | myscript instead of program | perl myscript.pl.
I want to be able to run my script via drag & drop.
There are a number of changes you have to make on Windows to make all of
these things work. Users typically stumble upon things that don't work one at
a time; leaving them confused whether they've made an error, there's a bug in
Perl, there's a bug in Windows, or the behavior they want just isn't possible.
This question is intended to provide a single point of reference for making
everything work up front; ideally before these problems even occur.
Related questions:
How do I make Perl scripts recognize parameters in the Win32 cmd console?
Running a perl script on windows without extension
Perl execution from command line question
How can I read piped input in Perl on Windows?
Perl on Windows, file associations and I/O redirection
How do I create drag-and-drop Strawberry Perl programs?
Note: The actions below require administrative privileges. For
steps utilizing the command prompt it must be launched via "Run as
administrator" on Windows Vista / Windows 7.
Associate *.pl files with perl
Run the following commands at a shell prompt:
assoc .pl=PerlScript
ftype PerlScript=C:\bin\perl.exe "%1" %*
Replace C:\Perl\bin\perl.exe with the path to your Perl installation. This
enables you to run myscript.pl instead of perl myscript.pl.
Default install locations are:
ActivePerl: C:\Perl
Strawberry Perl: C:\Strawberry
Add .PL to your PATHEXT environment variable.
This makes Windows consider *.pl files to be executable when searching your
PATH. It enables you to run myscript instead of myscript.pl.
You can set it for the current cmd session
set PATHEXT=%PATHEXT%;.PL
To set it permanently (under Windows Vista or Windows 7)
setx PATHEXT %PATHEXT%;.PL
Under Windows XP you have to use the GUI:
Right-click My Computer, and then click Properties.
Click the Advanced tab.
Click Environment variables.
Select PATHEXT, then click Edit.
Append ;.PL to the current value.
Make I/O redirection work
I/O redirection (e.g. program | myscript) doesn't work for programs started
via a file association. There is a registry patch to correct the problem.
Start Registry Editor.
Locate and then click the following key in the registry:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
On the Edit menu, click Add Value, and then add the following registry value:
Value name: InheritConsoleHandles
Data type: REG_DWORD
Radix: Decimal
Value data: 1
Quit Registry Editor.
Warning: In principle, this should only be necessary on Windows XP. In my experience it's also necessary in Windows 7. In Windows 10 this is actively harmful—programs execute but produce nothing on stdout/stderr. The registry key needs to be set to 0 instead of 1.
See also:
STDIN/STDOUT Redirection May Not Work If Started from a File Association
Perl Scripts on Windows 10 run from Explorer but not Command Prompt
If patching the registry isn't an option running program | perl -S myscript.pl
is a less annoying work-around for scripts in your PATH.
Add a drop handler
Adding a drop handler for Perl allows you to run a Perl script via drag & drop;
e.g. dragging a file over the file icon in Windows Explorer and dropping it
there. Run the following script to add the necessary entries to the registry:
use Win32::TieRegistry;
$Registry->Delimiter("/");
$perlKey = $Registry-> {"HKEY_CLASSES_ROOT/Perl/"};
$perlKey-> {"shellex/"} = {
"DropHandler/" => {
"/" => "{86C86720-42A0-1069-A2E8-08002B30309D}"
}};
Convert your perl scripts into batch files using pl2bat once they are ready to be run by users.
The trick works through the perl -x switch which, according to perldoc perlrun, makes Perl search for the first line looking like #!.*perl.
After following the instructions in the accepted answer, a double click still led to .pl files opening with Notepad in Windows 10 — even when perl.exe was set as the default file handler.
After finding Jack Wu's comment at ActivePerl. .pl files no longer execute but open in Notepad instead I was able to run perl scripts on double-click as such:
Select and right-click a .pl file
Use the "Open With" submenu to "Choose another app"
Select "Always use this app to open .pl files" (do this now – you won't get the chance after you have selected a program)
Scroll to the bottom of the "Other options" to find "More apps", and select "Look for another app on this PC"
Navigate to C:/path/to/perl/bin/ and select Perl5.16.3.exe (or the equivalent, depending on which version of Perl you have installed: but not Perl.exe)
Then the Perl icon appears next to .pl files and a double-click leads to them opening in Perl every time, as desired.
I tried the assoc and ftype methods and they didn't work for me.
What worked was editing this registry key:
Computer\HKEY_CURRENT_USER\Software\Classes\Applications\perl.exe\shell\open\command
It was set to:
"C:\Perl64\bin\perl.exe" "%1"
When it should be:
"C:\Perl64\bin\perl.exe" "%1" %*
It is the same content as the ftype, but for arcane windows reasons, I had to set it there too.
Like some others, I had set 'assoc' and 'ftype', but also had set Notepad text editor via the GUI, and when I tried to execute a script via the command line, Windows invoked Notepad to edit the script instead of running my script.
Using the GUI to instead point the .pl file association to the script-running executable was not much of an improvement, since it would invoke the executable on my script, but would pass no command-line arguments (even when I invoked my script from the command line).
I finally found salvation here which advised me to delete some registry keys.
Key quote:
"The problem is that if you have already associated the program with the extension via the Open With dialog then you will have created an application association, instead of a file extension association, between the two. And application associations take precedence."
In my case, following the instructions to use RegEdit to delete
HKEY_CLASSES_ROOT \ Applications \ perl.exe
where perl.exe is the name of my Perl executable, and then also deleting:
HKEY_CLASSES_ROOT \ .pl
seemed to solve my problem, and then (after re-executing 'assoc' and 'ftype' commands as shown in other answers) I could then execute scripts from cmd.exe and have them run with access to their command-line parameters.
Some other related information here.

Resources