I needed to pass id and password to a cmd (or bat) file at the time of running rather than hardcoding them into the file.
Here's how I do it.
echo off
fake-command /u %1 /p %2
Here's what the command line looks like:
test.cmd admin P@55w0rd > test-log.txt
The %1 applies to the first parameter the %2 (and here's the tricky part) ap...
For certain programs nothing beats the command line. Unfortunately, I have never seen good documentation or examples on how to write console applications that go beyond "Hello World". I'm interested in making console apps like Vim or Emacs. Well not exactly like Vim or Emacs but one that takes over the entire command prompt while it is...
When I open cmd on my laptop it is defaulting to the F: drive. This is troubling me does anyone know how it got that way or how to get it back to where it opens to the C: drive by default?
...
I need a way to recursively delete a folder and its children, is there a prebuilt tool for this, or do I need to write one?
DEL /S doesn't delete directories.
DELTREE was removed from Windows 2000+
...
How can I script a bat or cmd to stop and start a service reliably with error checking (or let me know that it wasn't successful for whatever reason)?
...
I need to be able to load the entire contents of a text file and load it into a variable for further processing.
How can I do that?
Here's what I did thanks to Roman Odaisky's answer.
SetLocal EnableDelayedExpansion
set content=
for /F "delims=" %%i in (test.txt) do set content=!content! %%i
echo %content%
EndLocal
...
On Linux/NPTL, threads are created as some kind of process.
I can see some of my process have a weird cmdline:
cat /proc/5590/cmdline
hald-addon-storage: polling /dev/scd0 (every 2 sec)
Do you have an idea how I could do that for each thread of my process? That would be very helpful for debugging.
/me now investigating in HAL sourc...
As I understand it, .bat is the old 16-bit naming convention, and .cmd is for 32-bit Windows, i.e., starting with NT. But I continue to see .bat files everywhere, and they seem to work exactly the same using either suffix. Assuming that my code will never need to run on anyhting older than NT, does it really matter which way I name my ba...
For some reason the Windows command prompt is "special" in that you have to go to a properties dialog to resize it horizontally rather than just dragging the corner of the window like every other app. Unsurprisingly this feature made it into P-P-P-Powershell as well -- is there any way around this via command prompt replacement or Window...
If I modify or add an environment variable I have to restart the command prompt (minor inconvenience). Is there a command I could execute that would do this without restarting CMD?
...
I have a directory with several subdirectories with files.
How can I copy all files in the subdirectories to a new location?
Edit: I do not want to copy the directories, just the files...
As this is still on XP, I chose the below solution:
for /D %S IN ("src\*.*") DO @COPY "%S\" "dest\"
Thanks!
...
I'm trying to write a Windows cmd script to perform several tasks in series.
However, it always stops after the first command in the script.
The command it stops after is a maven build (not sure if that's relevant).
How do I make it carry on and run each task in turn please?
Installing any software or configuring the registry etc is c...
How can I retrieve the current working directory of cmd.exe?
This seems possible. For example using ProcessExplorer, select CMD.exe, right click, properties, Image tab, "Current Directory" relects the directory set using the CD or CHDIR commands.
I've looked at the .NET Process and ProcessStartInfo classes (ProcessStartInfo.WorkingD...
I'm trying to read variables from a batch file for later use in the batch script, which is a Java launcher. I'd ideally like to have the same format for the settings file on all platforms (Unix, Windows), and also be a valid Java Properties file. That is, it should look like this:
setting1=Value1
setting2=Value2
...
Is it possible to ...
Hi, what is the best way to convert a UTF-16 files to UTF-8? I need to use this in a cmd script.
...
I have an MFC legacy app that I help to maintain. I'm not quite sure how to identify the version of MFC and I don't think it would make a difference anyway.
The app can take some parameters on the command line; I would like to be able to set an errorlevel on exiting the app to allow a bat/cmd file to check for failure and respond app...
How can I change my GNUemacs to open up a cygwin terminal rather then a cmd one with the shell command?
Closed as duplicate of How can I run Cygwin Bash Shell from within Emacs?.
...
In Unix/bash, I can simply say:
$ echo $?
to find out the return/exit code of a program, both from interactive and non-interactive shells.
Now, how can I do the equivalent in Windows/cmd.exe?
...
I need to grab the folder name of a currently executing batch file. I have been trying to loop over the current directory using the following syntax (which is wrong at present):
set mydir = %~p0
for /F "delims=\" %i IN (%mydir%) DO @echo %i
Couple of issues in that I cannot seem to pass the 'mydir' variable value in as the search stri...
I'm automating some source control software functionality using a dot bat script but given that our svn repos are hosted in a *NIX box, I'm facing the eternal case problem between these two worlds.
Is there any cmd.exe function to convert the value of the Windows system variable %USERNAME% to lower case?
Thanks much in advance!
...