![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Outputting variables & accepting keystrokes without pressing enter Hi! no1: Let's say that I have two variables: $var1 = "variable1" $var2 = "variable2" I would need to print out the values of these variables so that the output would be like: variable1_variable2 If I try output it: [PS] E:\>$var1 = "variable1" [PS] E:\>$var2 = "variable2" [PS] E:\>write-host "$var1_$var2" variable2 .... I can't get both of the values out. I also need to use this to specify an output file in cvs: [querystuff] | export-csv -path "c:\variables_$var1_$var2" I realize the difference between double quotes and single quotes. I just don't understand how to combine two variables. -------- no2 If I'm running some sort of loops and I need to query user for like "Press y to continue or n to quit" .... how can I do this so that user only needs to choose y and the query starts (without pressing enter)? |
My System Specs![]() |
| | #2 (permalink) |
| | RE: Outputting variables & accepting keystrokes without pressing enter # 1.- $var1 = "variable1" $var2 = "variable2" # the first variable's name is altered and PowerShell tries to expand # the variable $var1_, if it does not exist $null is expanded... "c:\variables_$var1_$var2" # ...if it exists, $var1_ is expanded $var1_ = 'oops!' "c:\variables_$var1_$var2" # to avoid this enclose the variable's name in '{}' "c:\variables_${var1}_$var2" # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # 2.- You can use the [Management.Automation.Host.KeyInfo]'s VirtualKeyCode Property to check which key was pressed. It also has a Character Property. Label the outer loop, then prompt the user and either continue or exit the outer loop. :myLoop foreach ($num in 1..10) { "`$num = $num" do { write-host Press y to continue or n to quit $action = $host.ui.rawUI.readkey('NoEcho, IncludeKeyDown') switch -r ($action.virtualKeyCode) { 89 { # <-- 'y' or 'Y' "`$num * 2 = $($num * 2)`n$('-' * 25)" break } 78 { # <-- 'n' or 'N' write-host Exiting myLoop sleep -m 200 break myLoop # <-- break out of the Foreach loop, labeled 'myLoop' } } # continue prompting if other keys were pressed } while ($action.virtualKeyCode -notMatch '89|78') } -- Kiron |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Why the "RunWorkerCompleted" never comes after pressing ENTER? | .NET General | |||
| Can't open pics by pressing enter or double click | Vista music pictures video | |||
| Pop-up to enter variables to pass to script | PowerShell | |||