I am trying to print photos from my application (Unity3D's game & script language is C# ) and I think using .bat is the simplest way to do that.
Batch file content :
"C:\windows\system32\mspaint.exe" /p "C:\Users\Jason\Documents\UnityProjects\Test-Printing\Assets\test.png"
This allow the application printing photo(screenshot from Unity3D) with mspaint(Microsoft Paint)'s "default print setting".
Is there any way to set print setting through Command Line in order to print photo without "default print setting".
The default printer is chosen because the last parameter in your code is omitted, so far, here are the possible parameters:
mspaint /pt [file name] [printer name]
for example:
"C:\windows\system32\mspaint.exe" /p "C:\Users\Jason\Documents\UnityProjects\Test-Printing\Assets\test.png" "Microsoft Print to PDF"
so in short, this should be helpful
"C:\windows\system32\mspaint.exe" /p "C:\Users\Jason\Documents\UnityProjects\Test-Printing\Assets\test.png" "INSERT_NAME_OF_YOUR_PRINTER_HERE"
Related
I have home profile file Microsoft.PowerShell_profile.ps1 in C:\Users\User\Documents\WindowsPowerShell. I want declare some variable, e.g $A = 5. When I start new powershell terminal and want display this variable ($A) result is empty (I don't see 5).
P.S.
If I put in this place other command, e.g. Write-Host "Test text" I see this when open new powershell terminal.
Somebody know why? :(
I have a requirement to have a small script on a Windows Server using PowerShell to convert files to PDF (from RTF). I've got a prototype using Word that works on my desktop machine, but the servers involved don't have Office/Word installed. Is there a similar way I can call Wordpad to achieve the same thing?
$documents_path = 'c:\projects\pbl\hi.rtf'
$word_app = New-Object -ComObject Word.Application
$document = $word_app.Documents.Open($documents_path)
$pdf_filename = 'c:\projects\pbl\hi.pdf'
$document.SaveAs([ref] $pdf_filename, [ref] 17)
$document.Close()
$word_app.Quit()
You would not be able to accomplish this goal using only WordPad because it has no automation interface like Microsoft Word has. You would need to investigate an alternative solution to achieve this.
This is old thread so no point in addressing OP question as such
However for the benefit of others landing here, this is a "Yes" Answer, I have not run it on a server, but understand there may be issues calling MS Print to PDF -- headless, for several reasons, including it uses the Graphics Device Interface. It works perfectly on a workstation.
It is done as a one line command along these lines, Input could be %1 with %2 for Output.
There are 2 WordPad.exe's to try :-)
This is the default American English one:-
%comspec% "C:\Windows\System32\wordpad.exe" /pt "%Input%" "Microsoft Print to PDF" "Microsoft Print to PDF" "%Output%"
OR my Locale British English one, which I target !
"%ProgramFiles%\Windows NT\Accessories\WORDPAD.EXE" /pt %1 "Microsoft Print to PDF" "Microsoft Print to PDF" %2
For a drag and drop wrapper see:-
Doc2PDF.cmd - Convert .Doc(x), .ODT, .RTF or .Txt to PDF & open them in SumatraPDF
P.S
A better replacement to WordPad is Jarte Pro and if you have a Portable WinWord.exe you could look at https://stackoverflow.com/a/2749172/10802527
I have a batch file which prompts the user a few times. I am looking to automate that with powershell. Is there any way to do this? I would need something like this:
Start-Process $InstallDir\Install.bat "y,*,$Version,y,y,y,y,y,y,y,y,y,y,y,y,y"
Install.bat runs an installation and there are a total of 16 prompts. The third I would like the be a variable that I have in my powershell script already, but the others will be static. Also, at the end of the script, you need to press any key to continue.
Is there any way to do this?
Depending on your batch file and what commands actually do the prompt, you might use input redirection <. Put the prompts into a text file pine by line and redirect that into your batch file.
Supposing the batch file prompts.bat contains the following commands...:
#echo off
set /P VAR="Please enter some text: "
echo/
echo Thank you for entering "%VAR%"!
choice /M "Do you want to continue "
if not ErrorLevel 2 del "%TEMP%\*.*"
pause
...and the text file prompts.txt contains the following lines...:
hello world
Y
n
End
...the console output of the command line prompts.bat < prompts.txt would be:
Please enter some text:
Thank you for entering "hello world"!
Do you want to continue [Y,N]?Y
C:\Users\operator\AppData\Local\Temp\*.*, Are you sure (Y/N)?
C:\Users\operator\AppData\Local\Temp\*.*, Are you sure (Y/N)? n
Press any key to continue . . .
(The del command shows two prompts here as it receives the RETURN behind Y which is not consumed by choice; since an empty entry is not accepted, the prompt appears one more time.)
Read-Host will display a prompt for entry, assigning it to a variable means you can then use that entry later in the script.
As your example is non-specific the below will only give you an idea of what you need to do.
$InstallDir = "C:\folder"
$Version = Read-Host -Prompt "Enter Version Number"
Start-Process "$InstallDir\Install.bat" -ArgumentList "y,*,$Version,y,y,y,y,y,y,y,y,y,y,y,y,y"
i am trying to run a batch file from a perl script but i am not able to handle the return of a batch file. below is my code
perl script:
// call a batch file
my $output =system("D:\\WORKSPACE\\CC_Triggers\\batch_file.bat");
// based on output check the status of the batch file
if($output==0){
print "success in trigger**********";
}
else
{
print "FAilure**********";
}
batch file:
set "java_output="
setlocal enableDelayedExpansion
//this will call a java program and get return value.
for /f "delims=" %%J in ('java -cp "PMDfileRead.jar;jxl.jar" PMDfileRead') do (
set "java_output=!java_output! %%J"
)
endlocal & set java_output=%java_output%
// check the ouput of java and act accordingly
IF %java_output% == 1 (
echo failed
exit(1);
)else (
echo succeeded
)
basically i am trying to validate an xls file and return flag from java code which is being called by a batch file and from ther i need to return back to perl script which i am not able to get. in case of success and failure, i am getting as "0" as output due to which output is success.. request to please correct my code or suggest me the best way to handle this.
edit: Sorry i somehow read past the comment by mpapec stating the same thing.
The Perl part is fine. If you always get a 0, it has to be the batch script acting up. Or the Java.
If you want to inspect the return value in Perl for anything except whether it is zero or not, then you would have to shift it right 8 bits.
my $output = (system("D:\\WORKSPACE\\CC_Triggers\\batch_file.bat")) >> 8;
But as you only check for zero or not, that should not be an issue here.
edit:
When using Windows, it is important to never define an environment variable ERRORLEVEL as that will mix up with the actual exit codes returned by applications. This is explained in more detail here: How do I get the application exit code from a Windows command line?
Replace your system() call with backticks instead:
A system() wrapped call returns the exit status of the command, whereas using ``'s returns the actual STDOUT (i.e. your echo statements)
For more info:
What's the difference between Perl's backticks, system, and exec?
i.e.:
my $output = `D:\WORKSPACE\CC_Triggers\batch_file.bat`;
Is it possible to get Powershell to read the stdout of an exe into a byte[] instead of the usual text processed array of lines?
Best I've been able to do is this:
cmd /c foo.exe > foo.tmp
$b = [io.file]::readallbytes('foo.tmp')
del foo.tmp
Yucky, not to mention it is not streamable. Any better way to do this?
Got some info from the PowerShell team. The short answer is that unfortunately, it is not easy. :-(
The medium length answer is: http://poshcode.org/2175.
The long answer is: Capture and Redirect Binary Process Output