I was wondering if there was any way to run the command prompt from Inno Setup's Exec function in a way which would hide the output from the user. Currently I have the below function which I'd like to do this for.
Exec(
'cmd.exe',
'/c ' + InstallPath + '\initdb ' + '-U postgres -A password -E utf8 --pwfile=' +
InstallPath + '\password.txt -D ' + DataPath,
'', SW_SHOW, ewWaitUntilTerminated, ResultCode);
I know you can add a flag to the Run section, but haven't really found anything analogous to that. Any help would be appreciated.
You should be able to change the SW_SHOW to SW_HIDE to hide the command window.
For example:
Exec(
'cmd.exe',
'/c ' + InstallPath + '\initdb ' + '-U postgres -A password -E utf8 --pwfile=' +
InstallPath + '\password.txt -D ' + DataPath,
'', SW_HIDE, ewWaitUntilTerminated, ResultCode);
For those using [Run] section, see How to run a CMD command without openning a new window in Inno Setup.
Related
I have tried a few of the prompts that are available through the fish config tool. All of them have had prompts that become progressively shorter with a smaller window width. I personally don't like this as I always want to see the folder and git branch that I am in.
Is there a simple setting (or a popular off the shelf prompt) that makes the prompt be full width regardless of window width.
You can run the command fish_config, it will open a new tab in your browser, then select the Prompt tab and you will see some pre-setup prompts. If any of those suits you then you need to configure a prompt by yourself. On terminal you can do:
Go to .config/fish (generally it is located in your home folder. Linux or macOS you can do: cd ~/.config/fish
Create a folder named functions (mkdir functions ; cd functions)
Create a file named fish_prompt.fish with the content bellow:
function fish_prompt --description 'Informative prompt'
#Save the return status of the previous command
set -l last_pipestatus $pipestatus
switch "$USER"
case root toor
printf '%s#%s %s%s%s# ' $USER (prompt_hostname) (set -q fish_color_cwd_root
and set_color $fish_color_cwd_root
or set_color $fish_color_cwd) \
(prompt_pwd) (set_color normal)
case '*'
set -l pipestatus_string (__fish_print_pipestatus "[" "] " "|" (set_color $fish_color_status) \
(set_color --bold $fish_color_status) $last_pipestatus)
printf '\f\r> %s%s#%s %s%s %s%s%s' (set_color brblue) \
$USER (prompt_hostname) (set_color $fish_color_cwd) $PWD \
(set_color normal)
end
end
Please, note that the code bellow is adapted from the Informative prompt
The Awesome Fish repository has some interesting prompts that you can install if you like.
How to escape spacing in the following power shell script? I tried `, ^ and even double quotation enclosing folder name with spacing but still hit directory not exist. The execution stopped at with "C:\Users\Super:" directory not exist
cmd /c C:\Users\Super Human\.nuget\packages\google.protobuf.tools\3.5.1\tools\windows_x64\protoc.exe -I C:\Users\Super Human\Desktop\School Service\School.Service.Student\Grpc\Protobuf\proto\exception\ -I ...
$dq=$([char]34)
$CommandLine=-join (
$dq,
'C:\Users\Super Human\.nuget\packages\google.protobuf.tools\3.5.1\tools\windows_x64\protoc.exe',
$dq,
' -I ',
$dq,
'C:\Users\Super Human\Desktop\School Service\School.Service.Student\Grpc\Protobuf\proto\exception\',
$dq,
' -I '
)
cmd.exe /c $CommandLine
I'm running a fairly simple sh script that automates a few telnet commands, but I've run into an issue.
One command requires an SOH character (normally sent using CTRL + A) followed by the command name, then enter. This is a snippet of that, but it doesn't work:
#!/bin/sh
(
echo open 12.34.56.78
sleep 2
echo -e "\u001""commandname"
echo -e "\n"
sleep 3
echo "quit"
) | telnet
What am I doing wrong? How can I send that SOH character via the script?
Use printf.
{
printf "open 12.34.56.78\n"
sleep 2
printf '\001commandname\n\n'
sleep 3
printf 'quit\n'
} | telnet
I am creating custom forms and adding it to the printer server properties using forms.vbs and running it through cmd. The script is as follows
cscript 'C:\Tools\forms.vbs' -a -n "DD" -u inches -h 7.48 -w 7.48 -t 0 -e 0 -b 7.48 -r 7.48
This works fine when running in command prompt.
Now I invoked this code to the powershell as follows and it also works fine
$formname = "DD"
$cmd = "cscript 'C:\Tools\forms.vbs' -a -n " + '"' + $formname + '"' + " -u inches -h 7.48 -w 7.48 -t 0 -e 0 -b 7.48 -r 7.48 "
Invoke-Expression $cmd
The issue started when I thought of checking the error handling thing for the powershell invoke expression.
In cmd when we give the expression as
cscript 'C:\Tools\forms.vbs' -a -n "DD" -u inches -h 7.48 -w 7.48 -t 0 -e 0 -b 0 -r 0
This will definitely throw error as per the notes given in the form.vbs and it will not create a form.
So when I invoked the same error-thrown script to my powershell, the form is not creating as well as it is not throwing any errors. So I request me to guide in this regard. Thanks in advance.
Invoke-Expression only checks if it's possible to run the command at all. For example, if cscript.exe cannot be found, Invoke-Expression will throw an ObjectNotFound exception.
It doesn't check the exit code of the command or in any way parse its output. You should be able to see the output however.
Make sure you don't mix single and double quotes inside your expression:
$formname = "DD"
# Note double quotes around C:\Tools\forms.vbs
$cmd = 'cscript "C:\Tools\forms.vbs" -a -n ' + '"' + $formname + '"' `
+ ' -u inches -h 7.48 -w 7.48 -t 0 -e 0 -b 7.48 -r 7.48 '
Invoke-Expression $cmd
Output:
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
Unable to add form DD, error code: 0x1A8. Object required
If you want your code to throw an exception, you need to parse the output manually, e.g.:
try {
$output = Invoke-Expression $cmd
if ($output -like "*error code*") { throw $output }
}
catch [System.Exception] {
$message = ($Error[0].Exception -split [System.Environment]::NewLine)[-1]
$message
}
Output:
Unable to add form DD, error code: 0x1A8. Object required
I have been using Start-Process to manage installs and uninstalls, and recently started using the same approach for arbitrary executables, which seems to be somewhat what you are trying to do, so...
$new.ExitCode > $null
$filepath = 'cscript.exe'
$argumentList = "C:\Forms.vbs"
$exitCode = (Start-Process -FilePath:$filePath -argumentList:$argumentList -wait -errorAction:Stop -PassThru).ExitCode
$exitCode
The VBS just throws up a messagebox and quits with a return code, like so.
MsgBox "Text"
WScript.Quit 4
After I close the message box I get that 4 back at the PowerShell console. With no Wscript.Quit, or no exit code provided, I get the expected 0 back.
Simple example, but maybe gets you close, assuming you can get the error code you need into a variable so you can return it from the VBS. Or maybe someone points out some nuance I am not aware of and we both learn something. ;)
I am new to PowerShell scripting. I have been given the task to understand what a PowerShell script is doing.
I am stuck at following line:
& $basePath\CPAU.exe -u $($sqlUser.UserName) -p $(ConvertTo-UnsecureString $sqlUser.Password) -ex "cmd /c (sqlcmd $($sqlArgs -join ' ') > $outputFile && echo TRUE > SUCCESS) || echo TRUE > FAILURE" -wait -nowarn -hide
It feels like the script is trying to execute some sort of sql command. However, I am not sure of starting "&" symbol.
Also, could CPAU.exe be an external in basepath? And what do -p, -u, and -ex enforce?
Next line:
if (!(Test-Path .\SUCCESS))
{
#some more code
}
In above if statement, what does .\SUCCESS mean? Doesn't Test-Path operate on some sort of path to test whether it exists or not?
& is the PowerShell call operator, which "runs a command, script, or script block". In your case it's running the external command CPAU.exe located in $basePath with the parameters -u, -p, -ex, -wait, -nowarn, and -hide. That command runs another command (the argument of the parameter -ex):
cmd /c (sqlcmd $($sqlArgs -join ' ') > $outputFile && echo TRUE > SUCCESS) || echo TRUE > FAILURE
The above uses cmd.exe (the Windows Command Prompt) to run sqlcmd $($sqlArgs -join ' '), redirect its output to the file $outputFile, and write "TRUE" to either the file SUCCESS if the command succeeded or to the file FAILURE otherwise.
|| and && are cmd operators for command chaining. || means "run the next command if the previous command failed". && means "run the next command if the previous command succeeded".
& $basePath\CPAU.exe -u $($sqlUser.UserName) -p $(ConvertTo-UnsecureString $sqlUser.Password) -ex "cmd /c (sqlcmd $($sqlArgs -join ' ') > $outputFile && echo TRUE > SUCCESS) || echo TRUE > FAILURE" -wait -nowarn -hide
This is some Powershell code, calling the executable CPAU.exe stored in $basePath passing a username and password and making it execute some CMD code:
cmd /c (sqlcmd $($sqlArgs -join ' ') > $outputFile && echo TRUE > SUCCESS) || echo TRUE > FAILURE
The cmd executes a SQL command given some predefined $sqlArgs, joined by a space. The whole command is redirected to $outputFile which is also expected to be predefined.
If the output of the command AND the ability to Echo TRUE on the CMD console is true, a file called SUCCESS is created receiving the redirected output. Else, if something fails but the echo TRUE happens, a FAILURE file is created.
The whole thing waits for everything to be complete, gives no warning and ...hides....
Whoever wrote this, needs a vacation.