Make System information Batch file - windows

How to create a batch file about system info and ip address and domain server etc. _ which will generate a output as txt file

You can put whatever Windows commands you want in a batch file and then redirect the output to a text file using >. E.g., you could create a batch file called test.bat and put the following commands in it:
#echo off
systeminfo
ipconfig /all
Then you could run test.bat from a command prompt as follows:
C:>test >outfile.txt
The output of the batch file, which would consist of the output from the commands you placed in it, would be redirected to a file named outfile.txt by the redirect operator, >. Note: it can sometimes take awhile for the output of the systeminfo command to complete, so, depending on your system, you may need to give it a minute to complete.
Alternatively, you could add the >outfile.txt at the end of commands within the batch file itself, though for every instance after the first one you need to use double greater than signs, i.e., >>, to append the output rather than wiping out what was in outfile.txt previously and creating a new version of that text file. E.g., you could have the following in test.bat:
#echo off
systeminfo >outfile.txt
ipconfig /all >>outfile.txt
You would then just use the following at a command prompt:
C:>test

Related

How to save cmd output as file name

I'm running a command line script on multiple PC's and i'm trying to save username as a file name so i can see who's information i'm viewing later on.
In the command line script i run Whoami and i'd like to save it as "user"."file type". I'm trying to do this in a command line script because I always do it manually in command line and am trying to automate this process so I can do it faster.
If you know how to do it in a better way do share.
whoami > test.txt
tells it to go to a file and "test.txt" will be generated wherever your CMD CurDir is.
You may use Windows Environment variables %USERNAME% and possibly %USERDOMAIN% if the domain is needed.
%USERNAME% does not return the domain by itself.
Full list of standard environment variables: How-to: Windows Environment Variables
Use these in the command as needed. For example:
dir > %USERNAME%.txt
If you need the domain in there:
dir > %USERDOMAIN%_%USERNAME%.txt
(using _ to separate domain and username instead of \ since filename cannot contain \)
Remember to use >> instead of > if you don't want the file to be overwritten each time the command is run.
You may want to direct errors and standard output as needed: Redirecting error messages from Command Prompt: STDERR/STDOUT

Execute several commands in one line, and save stdout into a file

In a batch file, I am trying to execute several commands in a single line:
start cmd /c "title SomeTitle & python SomeFile.py 1>SomeFile.txt & timeout /t -1"
The output file SomeFile.txt is created empty, and everything is printed directly to the terminal.
I've tried putting the python SomeFile.py 1>SomeFile.txt part within double-quotes.
However, I then get a The system cannot find the path specified error.
How can I work around this?

Automatically answer input prompt of an exe started within a windows batch

I have an InputPromptAutomation.exe that prompts for a user input when started and closes if the user input is s:
C:\>AutomateInputPrompt\InputPromptAutomation.exe
Input 's' to stop the application:
s
C:\>
My Problem: I want to automate the startup of the .exe, such that I can start it by double-clicking a StartInputPrompt.bat. How can I automatically pass the s input, such that InputPromptAutomation.exe starts AND exits upon executing StartInputPrompt.bat?
echo s | AutomateInputPrompt\InputPromptAutomation.exe
Here's an example of piping Dir into a new CMD instance
Echo dir | cmd /k
Put S then Enter in a file.
AutomateInputPrompt\InputPromptAutomation.exe < file.txt
Here's an example of doing a dir then a Type c:\windows\win.ini
File.txt (remember to press enter after the last line). This IS NOT a batch file (even though it is identical to one because I'm use CMD as a sample program).
dir
type c:\windows\win.ini
Then type
cmd /k < file.txt
This assumes the program is reading from StdIn, as most, but not all console programs do. EG when you see Press any key to continue the program is NOT reading stdin.
Start is an internal command name. Do not name batch files start as it will cause problems under some circumstances.

Background processes in batch with redirected output

I'm trying to run several background processes from a batch file and have the output directed to a file. Is it possible to do this in Windows? This is what I've tried but it end up directing the output of the start program rather then background process.
start myapp.exe > myapp.out 2>&1
Actually it is quite easy without using a helper batch file. You just need to run the application via cmd.exe instead, and make sure to escape the special characters so they pass through to cmd.exe.
You probably don't want to see an extra console window, so use the START /B option.
start /b "" cmd /c myapp.exe ^>myapp.out 2^>^&1
Each STARTed process must have its output directed to a unique file. Multiple processes cannot share the same output file.
I think the only chance you have is to create one batch file for each exe that you want to start. Inside the batch file you can redirect the output. The master batch file would then "start" the batch file, not the exe directly.
You just need to include an exit command at the end of each batch file:
start_myapp.cmd contains the following:
myapp.exe > myapp.out 2>&1
exit
then you can run
start start_myapp.cmd
and the output will be redirected

Win 32, script, process all files in directory

I need to process all txt file in some folder using a console application. The command looks similar to this:
convert input_file.txt -par1 -par2 -par3
How to write a batch processing all files in the folder, passing file name as parameter to console apllication? Another idea, what about a Python solution?
Use for
for %f in (*.txt) do #convert "%f" -par1 -par2 -par3
Note that I use # to suppress echoing of the command line at each iteration of the for loop. This is optional.
The above syntax is appropriate for use at the interactive console. When executing in a batch file, the %f must be replaced with %%f.

Resources