Run PHP CLI from Windows Powershell ISE - powershell

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';"

Related

Passing a powershell variable value to an adb shell command

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}

Linter shows error SC1036 for correct powershell script

In my Github project I have this snippet in my powershell script:
param (
[string]$f,
[string]$l
)
The Super-linter shows me this error:
SC1036: '(' is invalid here. Did you forget to escape it?
but the code itself works.
I also tried a disabling of this linter rule, but this was not working, unfortunately.
PowerShell scripts shouldn't have #!/bin/bash interpreter line (shebang). This interpreter line might confuse the linter making it run shellcheck (which is for bash/sh scripts) instead of PSScriptAnalyzer (the powershell linter).
The correct interpreter line for PowerShell on Linux/Mac is #!/usr/bin/env pwsh. 1

SQLCMD runs in CMD but error in vbs

The following code runs at the CMD line, but get error "Expected end of statement", Line: 1 Char 11.
sqlcmd -S DONALDLT-PC\SQLEXPRESS -E -i C:\SQL\append_ToTblPurchaseDetials.sql
Its failing because your syntax is incorrect. You can not execute shell scripts directly in visual basic. The statements/parameters need to be properly escaped and passed to some type of execute method. If you are already doing this, please add the entire code.

perl command prompt with arguments

Is it possible to start a command prompt from perl script using Win32::Process::Create package?
I am trying to start DOORS from perl script. The executable is present in C:\Program Files\DOORS\bin\runDOORS9.rck.
I need to start the runDOORS9.rck with the argument COL9 to change the Database.
Try the good old system() function. On Windows it would use the cmd.exe, the system shell, to execute the command.
Since what you try to launch doesn't seem to be an .exe file, potentially you would have to use the start command of the cmd.exe.
For example:
system(qq{start "" "C:\Program Files\DOORS\bin\runDOORS9.rck" COL9});
(The first "" is required due to quirky argument parsing of the Window's shell commands. See help start for more information.)

Call a bash script in perl

I am trying to call a bash script in perl, by doing this -
my $which_mpi = "/sw/tools/tacc/builds/carter/site/salt_which_mpi";
$mpi_stack = system("$which_mpi",-n);
the problem is that I want the script to execute when it is called by system command in line
$mpi_stack = system("$which_mpi",-n);
but the problem with this is while assigning the path in $which_mpi it automatically executes the script. So instead of me getting this value
WHICH_MPI : /sw/tools/salt/builds/carter/altd/bin/site/salt_which_mpi
I am getting the path with the output of the bash script like
WHICH_MPI : /sw/tools/salt/builds/carter/altd/bin/site/salt_which_mpiopenmpi 1.6.1
where openmpi 1.6.1 is the output of my salt_which_mpi bash script.
You can use perl's backtick operator
`bash -c "$WHICH_MPI"`
take a look at this question:
another stackoverflow question