Type command not working in Windows command prompt - batch-file

Correct me if I'm wrong, but the type command is supposed to display the contents of a text file in the Windows command prompt. But whenever I use the type command to display a text file, the output is only:
Unable to initialize device PRN
The command used is:
type C:\Users\Matthew\Desktop\Hello.txt
I don't know why it's doing this and I can't seem to figure it out. So if anyone could help me, it would be greatly appreciated.

You echoed a 'print' command response to your file.
Open it with Notepad to verify.
Type is working (that's what's in the file).

"Unable to initialize device PRN" is an odd error, you must be using an old version of Dos which is attempting to use a printer.
Which means you're either using the print command, or something you're trying to type is confusing the type command and returning an error.
set /p text=<type C:\Users\Matthew\Desktop\Hello.txt
echo "%text%" && pause

Related

Cannot send arguments to batch file converted to application via IExpress

I have made a batch file which contains personal data, so to hide it from other people and to post it, I decided to "encrypt" it converting it to exe via IExpress.
My batch file is named prime.bat and it is located in %userprofile%.
Here are the steps I ran with iexpress.exe:
Runned iexpress.exe.
Selected Create new Self Extraction Directive file
Selected Extract files and run an installation command.
Entered package title (Prime finder).
Selected No prompt..
Selected Do not display a license..
Selected prime.bat located in %userprofile% (C:\Users\%username%).
Entered cmd /c prime.bat in Install Program and left Post Install Command as is (<None>).
Selected Default (recommended).
Selected No message.
Entered C:\Users\username\prime.exe and did not check any of boxes below.
Selected No restart.
Selected to save SED file.
Package created successfully!
As the batch file works with arguments, it must be run from the cmd. When I clicked the file single from explorer it opened correctly. Because I had put an error message if there are no arguments, it threw expected error and exited with 1. If I type just prime.exe in cmd, the above happens, and same output is produced.
But, if I run file from cmd again, but specify arguments, I get an error message in a new window. As I don't use English language and do not have the permissions to change language, I will try to translate the output:
Syntax error appeared in command line's selections.
Type /? after the command for help.
So, I typed prime.exe /?, and a new window with help appeared. I think I am missing something in iexpress.exe options.
I solved my problem using:
prime.exe /c:"cmd /c prime.bat numeric_arguments"
Which should be used when you want to send arguments to an IExpress 'compiled' file as /c option specifies a new install command.

How to pass commands in a text file to an EXE running through the command line with batch?

I have a text file with lots of commands in it and I want to sent those commands to a software called thermocal. It is a console application. I found the command below, but it doesn't work for me.
Do I need to put this .exe file in the same folder of the batch file to make it work or any thing else?
type somefile.txt | Thermocal.exe
Batch scripts can be considered as a collection of lines you could also type in a command line prompt one after another. With respect to this it might be helpful for you, to play with cmd in order to get a feeling for what is happening.
About starting thermocal: Assuming thermocal is not part of PATH then the batch file either needs to change the current directory to the one with termocal.exe. Alternatively you might be able to call thermocal.exe with adding a path like C:\ProgramFiles\Thermocal\thermocal.exe . Play with cmd to find out, what works and what doesn't
When you are able to start thermocal from the command line prompt window, you can start experimenting with the call. You will probably end of with something like this in your command line window:
C:\ProgramFiles\Thermocal> thermocal argument1 argument 2
If this works, you can start with batch programming :)
Assuming your arguments are stored in somefile.txt like this:
argument1 argument 2
TYPE does nothing more than printing a file:
TYPE somefile.txt
Now you need to use the result of the output as command line arguments:
for /f %%i in ('type somefile.txt') do (thermocal.exe %%i)

CMD file will not run my command in the else block

I'm writing a CMD script to execute a Java program. The program requires at least one argument so I created an if else block to check that argument one %1 is not blank. When I run the script without providing argument one I get the expected you must provide an argument to run. But when I do provide the argument the program does not execute. Additionally if I don't have #echo off set, the entire script prints out as text in the window when I do provide the proper argument.
Here's the full script:
set APP_HOME=C:\Temp\Hammer
rem Set APP_HOME to the place where you installed Hammer
if ["%1"] == [""] (
echo you must provide a python script to run
) else (
java -cp %APP_HOME%\lib\jython.jar;%APP_HOME%\lib\hammer.jar;%CLASSPATH% bridenstine.hammer.main.Main %1 %2
)
I think this is a problem with the script and not the program itself because when I run the line that's in the else block by itself without the script,
java -cp C:\Temp\Hammer\lib\jython.jar;C:\Temp\Hammer\lib\hammer.jar;%CLASSPATH% bridenstine.hammer.main.Main argument1
The program executes normally. I've been looking at example scripts and cross referencing this site for CMD files and what I have seems to be valid. Do I have a syntax error?
Update:
I'm running the script like so,
cd C:\Temp\Hammer
bin\ProgramScript.cmd argument1
Update 2:
Someone pointed out that when they run this script they get an error message saying Java is not recognized as an internal or external command (the expected message when Java is not set on their PATH) But they made a good point that this means the script is in fact getting inside the else block. I then pointed out the following,
After I run the script with a valid argument it prints out the entire script as text on the command prompt. I am then able to mark the line from inside the else statement (that was printed), copy it, paste it, and it runs the program fine. So the Java command seems to be valid. But you make a good point that the script is obviously getting inside the else block...something is still going wrong here and it doesn't seem to be the program.
Note:
If relevant I am using Windows 8.1 and I am using the standard command prompt, not one that has administrative privileges (the results remained the same regardless of using a command prompt with administrative privileges).
I suggest to use
set APP_HOME=C:\Temp\Hammer
rem Set APP_HOME to the place where you installed Hammer.
if "%~1"=="" (
echo You must provide a Python script to run.
pause
) else (
java.exe -cp "%APP_HOME%\lib\jython.jar;%APP_HOME%\lib\hammer.jar;%CLASSPATH%" bridenstine.hammer.main.Main %*
)
It is always better to enclose an argument string in double quotes if it contains environment variables like CLASSPATH which might have a string value containing 1 or more spaces.
%* is expanded by all arguments passed to the batch file as argument, i.e. %1 %2 ...
It is best to always specify an application like java with full path and file extension as otherwise Windows has to search for a file with a file extension as defined in environment variable PATHEXT in current working directory and all directories defined in environment variable PATH. At least the file extension should be in the batch file if the program files directory of the application varies.
I can only offer a suggestion; I've not tried this.
I would try escaping each ; with a caret ^ thus:
java -cp %APP_HOME%\lib\jython.jar^;%APP_HOME%\lib\hammer.jar^;%CLASSPATH% bridenstine.hammer.main.Main %1 %2
(But I'll admit it's clutching at straws...)
You are missing you she-bang at the top of the script
#!/bin/bash

How to make the text file content appear on Command Prompt using C coding via VS2012

I am trying to create a text-based program.
I need that program to show whatever I put in a .txt into the command prompt.
*The program is text-based game that runs on command prompt wherein in the beginning, if the user keys in the necessary command to see the Intro of the game, the program (running on command prompt) will show the Intro story I have typed in the .txt file.
This will be coded by using C language via Visual Studio 2012
Does anyone know the code for this?
*Additional Details:
I am looking for the code to be put into the C code.
Like
if (user wants to read File 1)
{
PUT THE CODE HERE!
printf("Go to previous page?(1)")
scanf("%d",&previouspage);
if (previouspage==1)
{
Go to Previous page
}
}
Output on Command Prompt:
The content of File 1....
Go to Previous Page?(1)
TYPE command is used to display contents of a text file.
TYPE "C:\textfile.txt"
Refer to this link for more details.
check the TEE port here:
http://www.robvanderwoude.com/unixports.php
it will split output to console and to file simultaneously
This command shows a text file in a Windows prompt and MS-DOS window.
type c:\file.txt

Stupid Batch File Behavior. Tries to execute comments

I have tried prefixing lines with semicolons, 'REM', etc.. but no matter what when I run my batch file I keep getting "unknown command REM whatever"
"REM test" It is not recognized, and it is windows vista. I simply get "rem" output back to my console.
That's entirely normal behavior. Batch files are simply sequences of commands that are run one after another. So every line will get output to the console as if it were typed there.
H:\>echo rem test > test.cmd
H:\>test
yields the output
H:\>rem test
as if I typed rem test directly to the console.
You can suppress this by either prefixing the line with #:
#rem test
or by including echo off in the batch file:
#echo off
rem test
If I put ":: test" and execute it I get back "Test".
Can't reproduce here.
If I put "; test" it recursively executes itself
A semicolon at the start of the line seemingly gets ignored.
If you're talking about cmd.exe batch files under Windows, you can use:
rem this method or
:: this method.
For bash and a lot of other UNIX-type shells, you use:
# this method.
I'm pretty certain you're not using cmd.exe since that would give you an error like:
'rem' is not recognized as an internal or external command,
operable program or batch file.
rather then:
Unknown command ...
If you are using a UNIX-type shell, the # character is almost certainly what you're after. If you let us know exactly the shell you're using, we can probably help out further.
you probably created an UNICODE file. These files contain 2 bytes header named BOM
which is not shown by any editor but cmd attempts to execute them and fails.
To make sure this is indeed an issue: type any other command at the very beginning
of your file and see it throws the same error - for example #echo test
To fix it, just create a new plain text file and copy content of the original file there.
then remove the original file and replace it by the newly created one.
In my case the problems are line endings. Somehow Maven or the Jenkins pipeline running on a Linux machine changed the line endings from Windows style (CR LF) to Unix style (LF). Changing them back solves the issue for me.

Resources