I have a line that works in cmd prompt but I cant convert it to work powershell, I can run it without errors in powershell but it doesnt function how it does in cmd prompt
"C:\Program Files\Curl\curl-7.69.1-win64-mingw\bin\curl.exe" -F file=#C:\Documents\some.txt http://localhost/fileupload.php
I fixed it in case anyone comes across this one day
. ""C:\Program Files\Curl\curl-7.69.1-win64-mingw\bin\curl.exe"" -F ""file=#C:\Documents\some.txt http://localhost/fileupload.php""
I think your file=#C:\Doc... needs quotations. file=#"C:\Doc..."
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}
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.
So I'm using this console command to open a file using a specific application and then passing in a parameter (spacing used to make it more legible)
start C:\"Documents and Settings"\User\"My Documents"\Application_folder\Application.exe
"C:\Documents and Settings\user\My Documents\file_folder\file.type"
"Parameter1"
Now I want to be able to call this same command but in PowerShell ISE. I've tried a few variations but none work. I'm not all that familiar with PowerShell, so would anyone be able to school me on how to do this?
How about
& 'C:\Documents and Settings\User\My Documents\Application_folder\Application.exe' "C:\Documents and Settings\user\My Documents\file_folder\file.type" "Parameter1"
I cannot run PowerShell.exe interactively in a Cygwin rxvt or mintty terminal. Seems any session using a /dev/tty? or /dev/pts? pseudo terminal device. An instance using the junky windows console device /dev/console or /dev/cons? will work.
cygstart /bin/bash -li
launches the console version in the cruddy Windows Command Prompt which is the only place I can get an interactive PowerShell.
Works. Rxvt doesnt:
Nor does mintty:
I've tried all the echo -e | powershell.exe and powershell.exe </dev/null
I'm assuming when I see answers on Stackoverflow on this they are using Console's ... or am I missing something?
Why I cannot run PowerShell 2 from Cygwin? seems to run fine, just gets powershell v3 when he wants v2 ... wish I had that problem.
I've developed a powershell wrapper to call powershell scripts and commands from a Cygwin terminal session but cannot get the interactive option to work (if you give the wrapper no script or commands then you want to go interactive). see https://bitbucket.org/jbianchi/powershell/wiki/ for info on the wrapper script. It works for most powershell.exe calls and even acts like a "she-bang" if used in the first line of the ps1 script.
Today, typing powershell at a Cygwin bash prompt just works.
If you need to run powershell inside cygwin/babun, follow https://code.google.com/p/mintty/issues/detail?id=56#c64 . Bascilly, downloard or compile https://github.com/rprichard/winpty, copy it to your $PATH and then run
console.exe powershell
This also works with batch scripts that invoke powershell inside.
The solution I've found is to use http://sergeybelous.com/ (main site) Proxy32 proxywinconsole.exe program. If this program is in the path, my poweshell.bash wrapper will call it which will let you work interactively with PowerShell.
First Install cygwin in your system.
After that type bash on powershell terminal and you can access cygwin terminal.
PS C:\Users\username\1and1> bash
username#LWMT-14R25Q2:/mnt/c/Users/username/1and1$
I'm afraid I can't answer your question, but maybe I can help you a little further on your way with this:
I believe this is related to this issue, as discussed on the MinTTY Issue #56.
It goes into great detail as to how common cmd.exe shell applications work and interact, so much as they detail how common unix applications using their TTY abstraction layer work differently than Windows command line applications.
Script for running powershell on Cygwin minty:
blahblah#blahblahbin $ cat pwrshl
#!/usr/bin/bash if [[ ! -f "$1" ]] then
echo "Usage: $0 <PowerShellScriptFile>"
exit fi
echo "\n" | powershell -Command "& {$(<$1)}"
I am using mr on Windows and it allows running arbitrary commands before/after any repository action. As far as I can see this is done simply by invoking perl's system function. However something seems very wrong with my setup: when making mr run the following batch file, located in d:
#echo off
copy /Y foo.bat bar.bat
I get errors on the most basic windows commands:
d:/foo.bat: line 1: #echo: command not found
d:/foo.bat: line 2: copy: command not found
To make sure mr isn't the problem, I ran perl -e 'system( "d:/foo.bat" )' but the output is the same.
Using xcopy instead of copy, it seems the xcopy command is found since the output is now
d:/foo.bat: line 1: #echo: command not found
Invalid number of parameters
However I have no idea what could be wrong with the parameters. I figured maybe the problem is the batch file hasn't full access to the standard command environment so I tried running it explicitly via perl -e 'system( "cmd /c d:\foo.bat" )' but that just starts cmd and does not run the command (I have to exit the command line to get back to the one where I was).
What is wrong here? A detailed explanation would be great. Also, how do I solve this? I prefer a solution that leaves the batch file as is.
The echo directive is executed directly by the running command-prompt instance.
But perl is launching a new process with your command. You need to run your script within a cmd instance, for those commands to work.
Your cmd /c must work. Check if you have spaces in the path you are supplying to it.
You can use a parametrized way of passing arguments,
#array = qw("/c", "path/to/xyz.bat");
system("cmd.exe", #array);
The echo directive is not an executable and hence, it errors out.
The same is true of the copy command also. It is not an executable, while xcopy.exe is.