I am trying to run a command line in vb6 and it won't work because of a " character in the command.
Here is the code I can run in command line and it works but when doing it from the VB it gets screwed up.
AlarmSummaryUtility 10 TP=1;PT=4 "W h:m:s:F:p" /export
Following is VB script that does not work because I think the command already has "" around the one section:
Dim command As String
command = AlarmSummaryUtility 10 TP=1;PT=4 "W h:m:s:F:p" /export
shell "CMD.exe /c " & command
End Sub
The issue is that in the command I am trying to execute, it already has "W h:m:s:F:p".
Is there any other way to do this?
You need to enclose the quote with double quotes.
Dim command As String
command = "AlarmSummaryUtility 10 TP=1;PT=4 ""W h:m:s:F:p"" /export"
Related
Good day to all. After google-ing and trying various solutions, I'm a bit stuck with the following easy (at least it seemed so) task:
I have a powershell variable, say:
$simpleString = "Hello World and stuff"
I'm testing an Android app via ADB, where I need to pass this variable's value as a string:
.\adb.exe shell input text "$simpleString"
I get error
.\adb.exe : Error: Invalid arguments for command: text
followed by reminder on how to use "input" command by adb.
Update:
I've also tried the following workaround:
$myCmd = Write-output "adb.exe shell input text `"$simpleString`""
thus building a valid command for CMD and then run it via:
cmd /c $myCmd
but I still get same issue
Any help will be much appreciated, thank you.
OK, after some additional trial and error, I found a solution that worked for me (using back-ticks, single quotes and "wrapping" the command into another variable:
$myCmd = Write-output "adb.exe shell input text `'$simpleString`'"
& cmd /c $myCmd
Spelling-out the first command for easier perception:
$myCmd = Write-output {double quotes}adb.exe shell input text {back-tick}{single quote}$simpleString{back-tick}{single quote}{double quotes}
cd "C:\Program Files\GPSoftware\Directory Opus\"
followed by
dopusrt.exe /info documents\filelist1.txt,listsel,0
Attempting to run it like so;
2::
Run, %comspec% /k cd "C:\Program Files\GPSoftware\Directory Opus\" && %ComSpec% /k dopusrt.exe /info documents\filelist1.txt,listsel,0,, Hide
Return
Gives me an error. ==> The following variable name contains an illegal character: ", Hide"
It thinks, the commas in the second CMD command are AHK parameters.
I've tried quoting the second command in its entirety but the CMD window seem to only receive the first command.
Thank you.
The commas indeed are one problem, another problem is your usage of %comspec% /k.
Right now, what you're trying to, is use the Run(docs) command, where the parameters would be as follows:
Target = C:\WINDOWS\system32\cmd.exe /k cd "C:\Program Files\GPSoftware\Directory Opus\" && C:\WINDOWS\system32\cmd.exe /k dopusrt.exe /info documents\filelist1.txt
WorkingDir = listsel
Options = 0
OutputVarPID = , Hide
The comspec(docs) variable contains the path to cmd.exe and the /k switch(docs) means to run the specified command.
So, you of course don't want to specify these things twice. Just one at the start of the command. (Run a program (cmd.exe) with the specified parameters (/k, cd, "C:\Program Files\...))
And about the commas, in legacy syntax (you're writing legacy syntax here) you'll need to escape(docs) them with `,.
So in legacy syntax your finished command would look like this:
Run, %ComSpec% /k cd "C:\Program Files\GPSoftware\Directory Opus\" && dopusrt.exe /info documents\filelist1.txt`,listsel`,0, , Hide
And in modern expression syntax it'd look like this:
Run, % A_ComSpec " /k cd ""C:\Program Files\GPSoftware\Directory Opus\"" && dopusrt.exe /info documents\filelist1.txt,listsel,0", , Hide
I'd recommend ditching the legacy syntax and starting to just write expression syntax.
Here's a documentation page to get you started about the differenced between legacy syntax and expression syntax, if you're interested.
But really, this whole approach with cding to the directory where dopusrt.exe is seems really silly to me. Not seeing the point of it.
Should be fine to just run the dopusrt.exe program directly?
Run, % """C:\Program Files\GPSoftware\Directory Opus\dopusrt.exe"" /info documents\filelist1.txt,listsel,0", , Hide
I want to run a single AutoHotkey command. A script seems kindof overkill.
In bash and powershell, you can run a command by passing it in as a string to the shell:
pwsh -Command ls
bash -c ls
Is there a way to do this with AutoHotKey.exe? In the documentation, all I see is that you can pass the name of a script file to execute. If powershell supported process substitution <(ls), I could do
AutoHotKey.exe <(echo "ls")
But I don't think there's a way to do this in powershell.
Is there another way other than creating a complicated version of process substitution myself?
The linked docs state:
[v1.1.17+]: Specify an asterisk (*) for the filename to read the script text from standard input (stdin). For an example, see ExecScript().
For instance, from PowerShell:
'MsgBox % "Hello, world."' | AutoHotKey.exe *
I'm not sure if you're looking for what the other answer states, or then for this what I'm about to write:
You can pass arguments into an AHK script and those arguments are then found from the built in variable A_Args.
Example AHK script:
for each, arg in A_Args
output .= arg "`n"
MsgBox, % output
PowerShell command:
& "C:\Path\To\My\Script.ahk" arg1 arg2 "this is the 3rd argument" arg4
This would be if you have AHK installed. If you have some portable AHK setup, you'd pass in the example script to AutoHotkey.exe and then the desired arguments.
I am trying to run the powershell script from the command line along with the arguments but it is always failing with the below error. Can anyone help?
cmd /c "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe C:\start.ps1 -settings_override_xml /"<?xml version=/'1.0/'?><Settings><Keys>243</Keys></Settings>/""
Error:
< was unexpected at this time
Escape the double quotes in the middle with a backtick.
cmd /c "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe C:\start.ps1 -settings_override_xml /`"<?xml version=/'1.0/'?><Settings><Keys>243</Keys></Settings>/`""
Edit: To explain, it was reading your original command as:
Start command prompt with the command:
cmd /c "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe C:\start.ps1 -settings_override_xml /"
Then import the following as arguments or input for that command:
<?xml version=/'1.0/'?><Settings><Keys>243</Keys></Settings>/""
Hm, you're right, it's erroring on the < which is a reserved character, and I'm betting it'll error on > as well. Escape those and it should work.
cmd /c 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe C:\start.ps1 -settings_override_xml /"`<?xml version=/''1.0/''?`>`<Settings`>`<Keys`>243`</Keys`>`</Settings`>/"'
Tested that as working on my machine with no errors given.
This question is regarding dollar signs "$" $ in Windows PowerShell ISE.
I have PHP CLI and want to run one liner command scripts from the prompt in Windows PowerShell ISE.
php -r "$foo = 'foo';"
Just returns Parse error: parse error in Command line code on line 1 and I've narrowed it down to the pesky dollar sign which is significant in PowerShell. Can I escape it somehow?
I also tried
php -r '$foo = "foo";'
and get
Notice: Use of undefined constant foo - assumed 'foo' in Command line code on line 1
Yes, add a backtick in front of the dollar sign:
php -r "`$foo = 'foo';"
This is what you need:
"`$foo = 'foo';"