Can't run line command with AHK - autohotkey

Anyone why my parameters are not active please ?
thanks
Run, "C:\Program Files (x86)\rFactor\rFactor Dedicated.exe" "+oneclick +profile "serveur01""

Autohotkey doesn't need quotes for the program - it is not the same as batch scripting.
If your program requires quotes for the commandline parameter, then you include quotes.
But you don't have any spaces in the parameters, so you don't need any quotes at all.
Run, C:\Program Files (x86)\rFactor\rFactor Dedicated.exe +oneclick +profile serveur01

Related

Why can't Chrome's --print-to-pdf PowerShell command generate a pdf to some folders?

I have an app deployed on a server that runs a PowerShell command to launch headless Chrome and print a website as a PDF but it fails to generate the file.
I tried running the command directly from PowerShell. It seems that when I try to generate the file in C:/Program Files or a folder within it, it silently fails. But then to some folders, like Download or where the app is deployed, it generates it fine. And to even other locations, like C:, it shows that I am missing permissions.
Chrome is installed on the server. I also tried this on my local machine and I'm getting the same results.
This is the failing command I'm using to try and generate a pdf within Program Files folder:
Start-Process -FilePath "C:\Program Files\Google\Chrome\Application\chrome.exe" -ArgumentList "--headless","--print-to-pdf=C:\Program Files\pdfFromPowershell.pdf","--no-margins","--enable-logging","https://google.com"
Command succeeds if the target folder is pointed to Downloads.
Why can't I generate a PDF within C:/Program Files folder (and possibly others) and what can I do to fix this?
Edit: I am actually using the following syntax for the command:
$chrome='C:\Program Files\Google\Chrome\Application\chrome.exe'; & $chrome --headless --print-to-pdf-no-header --print-to-pdf='C:\Program Files\temp\pdfFromPowershell.pdf' --no-margins https://google.com
The issue comes from Chrome.exe not understanding PowerShell's way of quoting, where it just wants double quotes for the path:
Start-Process -FilePath "C:\Program Files\Google\Chrome\Application\chrome.exe" `
-ArgumentList "--headless",
"--print-to-pdf=""C:\Program Files\pdfFromPowershell.pdf""",
"--no-margins","--enable-logging","https://google.com"
The need for double double-quotes only comes when you're looking to escape the quotes within a pair of double quotes, whereas single quotes would work too. I know, confusing, so here's an example:
# escape the double quotes inside double quotes by doubling quotes inside.
"--print-to-pdf=""C:\Program Files\pdfFromPowershell.pdf"""
# using single quotes this should work as well, where only one pair is needed.
'--print-to-pdf="C:\Program Files\pdfFromPowershell.pdf"'
For windows 7/8/9/10/11 users native inbuilt MSEdge can do this very simply (no need to add another chromium or slow it down it is instant from a cmd line or shortcut)
For 32bit users run
"C:\Program Files\Microsoft\Edge\Application\msedge.exe" --headless --print-to-pdf="C:\whichever folder\PDFfromCMD.pdf" https://google.com
For 64bit users run
"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" --headless --print-to-pdf="C:\whichever folder\PDFfromCMD.pdf" https://google.com
Note --no-margin or --no-margins does nothing other than make the line longer, and older --export-tagged-pdf is no longer needed as its the current default, however you may wish to add --print-to-pdf-no-header or some other options to slow down premature building as its so fast the html may not have fully loaded so perhaps you may use --run-all-compositor-stages-before-draw
Microsoft docs will refer you to a list of switches for chrome which can be found at https://peter.sh/experiments/chromium-command-line-switches/
so run this way we can print and view this question (and answers) note I did not switch off headline(s) so have both a timestamp and full title, and in the footline(s) a hyperlink to this page and number of pages.
"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" --headless --print-to-pdf="%userprofile%\desktop\pdfFromcmd.pdf" --enable-logging https://stackoverflow.com/questions/72018079/why-cant-chromes-print-to-pdf-powershell-command-generate-a-pdf-to-some-fold && "%userprofile%\desktop\pdfFromcmd.pdf"

Running PowerShell Script from shortcut with spaces in path

One of our users needs to invoke a PowerShell script from a shortcut, as using the command line is probably beyond their abilities. The path of the script contains spaces, and I have been unable to successfully get the script to run from the shortcut. The target of the shortcut is:
powershell.exe -file "C:\Users\xxxxx\xxxx xxxx\Finance - Documents\Secure\xxx (Finance Officer)\Rent\Data File Loader - XXXXX\InvokeDataLoader.ps1"
(I have replaced names of people and the company with x's)
Clicking on the shortcut just briefly opens a cmd window (I think) so I have have been trying to diagnose the problem by running the command in cmd.exe. However when I try to do that I get an error message that it cannot find the path "C:\Users\xxxxx\xxxx" i.e. it is splitting the path on the first space. Enclosing the path with single or double quotes does not change this, and if I try to escape the spaces with backticks I get a message that the path does not exist.
You actually don't need to change the PowerShell script itself to do this. When making the shortcut, simply set the target to:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe "C:\Users\xxxxx\xxxx xxxx\Finance - Documents\Secure\xxx (Finance Officer)\Rent\Data File Loader - XXXXX\InvokeDataLoader.ps1"

javac powershell classpath separator

So I'm aware that different operating systems require different classpath separators. I'm running a build of windows where CMD has been replaced with Powershell which is causing problems when using the semi-colon separator.
The command I'm trying to run begins with cmd /c to try and get it to run in command prompt instead but I think when PowerShell is parsing the whole command it sees the semi-colon and thinks that is the end!
My whole command is:
cmd /c javac -cp PATH1;PATH2 -d DESTINATION_PATH SOURCE_PATH
I have tried using a space, colon and period to no avail. Can anybody suggest a solution?
This is my first question on stackoverflow, hope the community can help and that it will eventually help others. :)
I suggest you start the process in the following way using Powershell
Start-Process cmd.exe -ArgumentList "/c javac -cp PATH1;PATH2 -d DESTINATION_PATH SOURCE_PATH" -NoNewWindow
Running javac in CMD shouldn't be required. Just put quotes around arguments that (may) contain whitespace or special characters. I'd also recommend using the call operator (&). It's optional in this case, but required if you put the executable in quotes (e.g. because the executable or path contains spaces or you want to put it in a variable).
& javac -cp "PATH1;PATH2" -d "DESTINATION_PATH" "SOURCE_PATH"
You could also use splatting for providing the arguments:
$javac = "$env:JAVA_HOME\bin\javac.exe"
$params = '-cp', "PATH1;PATH2",
'-d', "DESTINATION_PATH",
"SOURCE_PATH"
& $javac #params
javac -classpath "path1:path2:." main.java does the trick in powershell. the cmd doesn't need the doble quotes however while using powershell we need to put the quotes and it works smoothly.

Passing property values with spaces to Ant

I'm trying to pass a space-separated value $env:tt to Ant under PowerShell
$env:tt="val1 val2"
Here are the commands I've tried:
ant '-DTest="$env:tt"'
ant -DTest=$env:tt
With the above commands, Ant doesn't interpret $env:tt. The value of test becomes $env:tt.
ant -DTest="$env:tt"
I got the following response under PowerShell
PS C:\> ant -DTest="$env:tt"
>>
It seems that this command is not finished, and PowerShell expects me to enter some characters to terminate the command.
Any idea on how to do this?
variables are expanded inside double quotes but not when inside single quotes.
ant "-dest=$env:tt"

psexec not executing command once I pass in command line arguments

I have to run the following command remotely on another server, the arguments are prefixed with !=:
wdrspc.exe !=BATCHTEST1,LGTY_PLAN_01
This works (but the exe fails because I'm not passing in any arguments):
psexec \\kiklogiappsd "c:\Program Files (x86)\Logility\SPC8.0\wdrspc.exe"
This does not work (psexec says system cannot find the file specified):
psexec \\kiklogiappsd "c:\Program Files (x86)\Logility\SPC8.0\wdrspc.exe !=BATCHTEST1,LGTY_PLAN_01"
I'm stumped, is it the != syntax throwing off psexec?
The correct command line would be:
psexec \\kiklogiappsd "c:\Program Files (x86)\Logility\SPC8.0\wdrspc.exe" !=BATCHTEST1,LGTY_PLAN_01
The program arguments should not be in quotes with the program path, or they'll be interpreted as part of the program path. When you quote a space in a command line argument, that tells the shell that the space is part of the argument, rather than separating two arguments. That's why you quote anything in C:\Program Files (x86). But you want an argument-separating space between the program path and its arguments.