I hope I am not out of OT I have a problem with powershell v2.0 with win 7 I am writing a dos batch file whose task, among other things, is to download a file. To do this I am using powershell 2.0 by win 7. I don't know this language and I can't go on anymore.
powershell.exe -NoExit -Command "& {(New-Object System.Net.WebClient).DownloadFile("https://downloads.html/example.exe","C:\tmp\example.exe")}"
the error he gives me is the following
')' missing in the method call. In row: 1 car: 52
& {((New-Object System.Net.WebClient) .DownloadFile (<<<< https://downloads.ar
duino.cc/arduino-1.8.13-windows.exe,C:\tmp\arduino-1.8.12-windows.exe))}
CategoryInfo: ParserError: (CloseParenToken: TokenId) [], Paren
tContainsErrorRecordException
FullyQualifiedErrorId: MissingEndParenthesisInMethodCall
thanks
The syntax is
(New-Object System.Net.WebClient).DownloadFile($url, $output)
I didn't run your code but it looks like you're missing a parentheses before ".download".
Related
I'm trying to parse a few commands to Houdini's Python module called Hython.
And I'm doing this through os on windows.
My command looks like this:
command = '''"c:\\Program Files (x86)\\Steam\\steamapps\\common\\Houdini Indie\\bin\\hython.exe" -c \
"import sys; sys.path.append('d:\\Cloud\\OneDrive\\Dokumenter\\GitHub\\tutorialTools\\utils'); \
import houUtils; houUtils.runReduction(\'%s\',\'%s\')"''' % (assetDir, amount)
os.popen(command)
I've tried all the tricks on quotations I could think of, but I'm getting a :
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes
in position 49-50: truncated \uXXXX escape
Any kind of help would be appreciated
First I tried adding to the command by separate lines:
"command +=" but this stopped me quickly.
I've tried doing the initial path with r'c:\...'
The entire problem seems to be connected with writing paths inside a quotation.
In my DOCKERFILE I'm running some PowerShell script which creates a custom event log (on Windows Server), then writes an entry. [I should add that I'm currently doing this only for debug purposes.]
The script/command which creates the event log appear to execute without any problems, but an exception is thrown when writing to the log using...
RUN powershell.exe -command Write-EventLog -LogName "my_log_name" -Source "my_source" -Message "EventLog created by DOCKERFILE." -Category 0 -EventID 0 -EntryType Information
The following exception is thrown...
Write-EventLog : A positional parameter cannot be found that accepts argument
'created'.
At line:1 char:1
+ Write-EventLog -LogName my_log_name -Source my_source -EntryType Messag ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Write-EventLog], Parameter
BindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
.Commands.WriteEventLogCommand
I also tried wrapping "EventLog created by DOCKERFILE." in parentheses but then it complained about the word by.
Why does it seem unable to parse "EventLog created by DOCKERFILE." as a string argument, but is instead parsing the words within the string?
UPDATE
Even if I wrap the command in double-quotes and the individual strings in single quotes, I get the same error.
UPDATE 2
Removing the quotes and escaping the spaces doesn't work either.
You need to use ` to escape the spaces:
RUN powershell.exe -command Write-EventLog -LogName my_log_name -Source my_source -Message EventLog` created` by` DOCKERFILE. -Category 0 -EventID 0 -EntryType Information
See: https://docs.docker.com/engine/reference/builder/#escape
This works for me from cmd (except for the unknown source). I'm not sure if docker has issues with single quotes. Double quotes are special in cmd. Note that new-winevent has replaced write-eventlog.
powershell write-eventLog my_log_name my_source 0 information 'EventLog created by DOCKERFILE.' -category 0
How to create Antlr tree Parser Diagram through CMD Line?
Currently i have some grammar content which am trying to parse as Tree in Antlr.
Currently am executing this grammar file thriugh CMD line
C:\Users\mohan\ANTLR>java -jar antlr4-4.1-complete.jar grammar.g4
After creating the Lexer and Parser java files i recommand to use the ANTLR testing tool taht provided in the ANTLR jar org.antlr.v4.gui.TestRig
java -cp .;D:\Work\lib\antlr-4.5.3-complete.jar org.antlr.v4.gui.TestRig <GrammarName> <startRuleName> -gui [input-filename]
should do the trick.
you can read more about this in The Definitive ANTLR 4 Reference its have more details on how to use it.
pesonaly i prefer using notepad++ ANTLR plugin to test my grammar its basicly does the same thing except its more comfterble for me not to always go back to the Command Prompt after every change in my grammar.
here is a link to the notepad++ plugin and how to install it :notepad++ antlr pigin
After writing my grammar file for my corresponding code block, i have compiled and executed as follows
set path=%path%;C:\Program Files\Java\jdk1.8.0_92\bin
set path=%path%;C:\Users\Mohan\ANTLR\antlr-4.5.3-complete.jar
java -jar antlr-4.5.3-complete.jar Grammar.G4
javac -cp .;antlr-4.5.3-complete.jar Grammar*.java
java -cp .;antlr-4.5.3-complete.jar org.antlr.v4.gui.TestRig Grammar prog -gui
C:\Users\Mohan\ANTLR> java -cp .;antlr-4.5.3-complete.jar org.antlr.v4.gui.TestRig Grammar prog -gui
After Compiling all commands in Command prompt give Ctrl + Z if you are using Windows and Ctrl + D if you are using **nix, to generate parser diagram.
I am extreme newbie to powershell. I have a script that I want to pass a URL as a parameter. The url runs a PHP process that creates and downloads a PDF file then the script prints the pdf and then deletes the pdf. I cannot get the URL parm to work.
Below is my script
$w=$args[0]
Start $w
$Directory = "C:\Users\pslessor\downloads\"
Get-ChildItem -path $Directory -recurse -include *.pdf | ForEach-Object {Start-Process -FilePath $_.fullname -Verb Print -PassThru | %{sleep 5;$_} | kill }
Remove-Item C:\Users\pslessor\downloads\* -include *.PDF
This script is being executed by a batch file PrintPl.bat
SET ThisScriptsDirectory=%~dp0
SET PowerShellScriptPath=%ThisScriptsDirectory%PrintPl.ps1
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '%PowerShellScriptPath%' %1";
And I am testing with testprint.bat
C:\Wget\PrintPl "https://partners.wayfair.com/print_shipping_docs.php?Print=1&printPackingSlips=1&PackingSlipPOs=CS287851107"
The URL is all in one string this editor is forcing the line feed at .php?
The Error I am getting is
The string starting:
At Line:1 Char:25
+ & 'C:\Wget\Printpl.ps1' <<<< 'https://partners.wayfair.com/print_shipping_docs.php?print;
is missing the terminator: '.
At line:1 Char:85
+ & 'C:\Wget\PrintPl.psl' 'https://partners.wayfair.com/print_shipping_docs.php
?print; <<<<
+ CategoryInfo :ParserError: <https://partner...docs.php?print;:
String> [], ParentContainsErrorRecordException
+ FullyqualifiedErrorid : TerminatorExpectedAtEndOfString
'printPackingSlips' is not recognaized as internal or external command,
Operable program or batch file.
'PackingSlipPOs' is not recognized as an internal or external command,
operable program or batch File
This is happening because when you pass the arguments the command interpreter expands your variables and see this:
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& 'C:\Wget\PrintPl.ps1' https://partners.wayfair.com/print_shipping_docs.php? Print=1&printPackingSlips=1&PackingSlipPOs=CS287851107"
So the command that it is trying to execute is C:\Wget\PrintPl.ps1, and it assumes that what comes next are arguments. Since what it is passed has a space, and is not enclosed in quotes or double quotes it assumes that it is multiple arguments. It sees it as:
Execute this script: C:\Wget\PrintPl.ps1
With the following arguments:
$Args[0]=?
$Args[1]=Print=1&printPackingSlips=1&PackingSlipPOs=CS287851107
To stop this from happening you will need to enclose the URL in quotes as well, so your command should look like this:
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '%PowerShellScriptPath%' '%1'"
Edit: Ok, that didn't work for your case. So we're going to change this a little bit. Instead of -Command I'm going to suggest you use -File. So your Powershell execution line within the batch file will look like this:
PowerShell -NoProfile -ExecutionPolicy Bypass -File "%PowerShellScriptPath%" %*
You should be able to run the batch file exactly as you previously had been. I'm fairly confident that will work for you.
I'm trying to figure out how to call a PowerShell script with spaces in the filename as a Delphi build event.
From CMD I have to call powershell.exe -Command "& 'Filename With Spaces.ps1'" which works fine.
Delphi on the other hand doubles the ampersand sign and is trying to turn the command into two commands.
I have tried to set this as the build event:
powershell.exe -Command "& '$(PROJECTDIR)\Prebuild.ps1' $(PROJECTDIR)"
What gets executed by MSBuild is:
powershell.exe -Command "&& 'D:\SVN\AccuLib 3.0\VCLUI\Prebuild.ps1' D:\SVN\AccuLib 3.0\VCLUI"
So what does it take to call a ps1 file containing spaces from a Delphi build event?
Try the File parameter instead, it doesnt require an ampersand:
powershell.exe -File "Filename With Spaces.ps1"
To use an ampersand sign you can create an intermediate cmd script.
Delphi build event:
Prebuild.cmd "$(PROJECTDIR)"
Prebuild.cmd file:
powershell.exe -Command "& 'Filename With Spaces.ps1'"