Run alias command from command prompt in new command prompt - windows

So I've set up a file with some aliases for commands that I commonly use. I added it to the registry like in this answer.
I want to use this alias like so:
>cmd /k newalias
'newalias' is not recognized as an internal or external command,
operable program or batch file.
So this alias cannot be used.
If I type >cmd /k newalias again, now it works, so the problem seems to be that the command is being run before the doskey commands in the alias file are executed.
Is there any way to wait until after these aliases are created before running the command?

strange behaviour, but if you use doskey after you import your macro that is working :
cmd /K "doskey /macrofile=c:\temp\macros.txt & doskey /macros >null & newalias"
edit the above commant doesnt work, newalias has to be written manually in the console.

Related

windows bat file using start cmd /k with doskey not work

I tried to use start cmd with custom doskey file, but failed.
1.doskey
ls=dir /b $1
start "title" cmd.exe /k doskey /macrofile=1.doskey && ls .
Prompted
ls command is not recognized
Two issues:
Issue 1
The && will be interpreted by the shell you run this command from and not the shell in the window, so you are running doskey /macrofile=1.doskey in the new window but ls . in the old one.
The solution is to surround the whole command that should be passed to the new window with doublequotes:
start "title" cmd.exe /k "doskey /macrofile=1.doskey && ls ."
Alternatively you could escape both & characters with ^:
start "title" cmd.exe /k doskey /macrofile=1.doskey ^&^& ls .
...however, this will just uncover issue 2, so keep reading.
Issue 2
As you can deduce (sort of) from the DOSKEY docs, you cannot run a macro from a command that you didn't type in manually (after all, DOSKEY is a tool to process interactive input from a user):
To run a macro, type the macro name at the command prompt, starting at the first position. If the macro was defined with $* or any of the batch parameters $1 through $9, use a space to separate the parameters. You cannot run a doskey macro from a batch program.
(Emphasis mine.)
This talks only about batch files, but it applies to any non-interactive way of entering a command - and passing it to cmd /c or cmd /k is one of them (since you aren't typing the command into the new shell, it's run automatically on startup of the shell instead).
Based on how you described your intent ("use start with custom doskey file"), I assume you added the ls . only to test whether it works. In that case, just remove the whole && ls . part and try ls . manually in the new window, and you'll see that it does work!
In case that's not what you wanted, and you actually intended to run DOSKEY macros from that "cmd /k" command line or a batch file, you are out of luck - instead, you could call a batch file that contains functions and use that, or create custom batch files instead of macros.

use root cmd window to execute commands in new cmd window

i'm trying to make a batch script for running my Java files. I've found out that there is no way to prevent auto-closure of a batch script(except using pause keyword, tho it just waits for key press). I've also discovered that starting a new window will cause only main windows to close, not the new one too so i want a way that the command SET /P file=Java file: is executed in the new window(I got the new window by using the start keyword. Is there any way to accomplish this without downloading other softwares? this is the code i came up with yet:
cd "C:\Users\DEVDHRITI\Desktop\Files&Folders\HMMMMM\programs\java programmes"
set /P file=Java file to execute:
java %file%^.jar
start
I guess you're looking for that :
cd "C:\Users\DEVDHRITI\Desktop\Files&Folders\HMMMMM\programs\java programmes"
start cmd /V:ON /K "#set /P "file=Java file to execute: " && java -jar !file!^.jar"
EDIT: Using expansion with /V and use of /K instead of /C to keep the cmd windows open.
Explanations : To launch a console process in another windows and keep it open after the end of this process console we launch another cmd process with the start command. We use /V:ON to use delayed expansion by default, meaning modified variables (like the one we prompt, %file%) will be expanded on the fly with ! (so !file! instead of %file%). We use /K to tell to this cmd process to not close when provided commands end. To this cmd process, we provide the following commands :
#set /P "file=Java file to execute: "
This one will ask for the jar filename (without extension) to launch.
The # means "do not echo the command itself on the console stdout" for a nice display.
java -jar %file%^.jar
This one launch the java interpreter (JVM) with the filename of a jar file to execute through the -jar parameter, filename build from the previous prompt and the .jar extension. The ^ here escapes the ., it seems not useful here but maybe your script/env requires it.
We link the both commands with && which means : _if left command from && is successful (it exits with ERRORLEVEL 0) then execute the right command from &&.

How to call an executable file directly in notepad++?

In windows,I use the Notepad++ to write tex file, in the "run..." dialog,I input that:
cmd /k D:\CTEX\MiKTeX\miktex\bin\xelatex $(FULL_CURRENT_PATH)
then run it,however the result shows that 'xdvipdfmx' is not an executable file. But I am sure that I have add its path to the system environment variable,and when I direct run it in the terminal, it's ok.
So,I want to know what I should do to run it in the notepad++ correctly.
Try these improvements:
enclose paths into quotes to avoid problems with spaces
add .exe to executable file name
test the full command in command prompt to see if it works (replace $(FULL_CURRENT_PATH)) with actual file name
please let me know the result
Your example after changes:
cmd /k "D:\CTEX\MiKTeX\miktex\bin\xelatex.exe" "$(FULL_CURRENT_PATH)"
Test it in command prompt like:
cmd /k "D:\CTEX\MiKTeX\miktex\bin\xelatex.exe" "D:\Data\MyDoc1.tex"

Adding cmdline (win7) as an Eclipse console view

I've seen it in linux. There's a console you can open that is just a shell. I want the same thing in windows only with either cmd, or with git bash. (MINGW32). I tried googling it but just got flooded with articles about egit and normal git bash.
If you have msysgit, you can use it from a regular cmd session:
Launch c:\windows\system32\cmd.exe /k <path\to\your\msysgit>\git-cmd.bat, and you can type in that cmd windows regular git commands.
For a bash session: c:\windows\system32\cmd.exe /k <path\to\your\msysgit>\git-bash.bat.
Note that you need to modify those bat:
git-cmd.bat: add a rem before the setlocal command, and before the start at the end.
git-bash.bat: add a rem before the setlocal command.
So you can add to your Eclipse an external tool which will open a cmd in your console:
Except, instead of calling C:\windows\system32\cmd.exe (in the "Location" field from the picture above), you could call directly: C:\windows\system32\cmd.exe /k <path\to\your\msysgit>\git-bash.bat.
By 'msysgit', I refer to whatever name you gave to the uncompresdsed portable version of "Git For Windows": download it there.
And then you could type git command within the Eclipse console (including a bash session)!
After testing, the color codes get in the way, even if git works:
git-cmd.bat:
git-bash.bat:

Launch new command line and exucte in that shell

This must be a real dumb question. And I cant figure out how.
What I want to do is launch a new command line with some arguments and excute some commands there.
Here is what I have in my .cmd
CMD /k %EnvInstallPath% %wo% %var%
cd /d %wo%\src
When I execute test.cmd, I see that the directory changes to %wo%, but the further cd src is not executed. I need to cd to a directory and execute few other commands.
When you run cmd with /k the console runs the command and then resumes with the prompt. I'm guessing that what you want is to run the command and resume with the next one, so you need to run cmd with /c instead.
put the other commands in a different bat file and
start AFewOtherCommands.bat

Resources