powershell.exe -command get-clipboard modifies my terminal font if redirected - windows-subsystem-for-linux

I'm running bash on ubuntu on wsl2. I can run
powershell.exe -command get-clipboard
to output the contents of the clipboard. That runs great. However, if I try to redirect the output at all, e.g.:
powershell.exe -command get-clipboard | cat
foo=$(powershell.exe -command get-clipboard)
powershell.exe -command get-clipboard > /dev/null
foo=`powershell.exe -command get-clipboard`
it changes the font of my whole terminal to 8x12 RasterFont. And I have to change it back to Consolas. What's going on? How do I capture the contents of the clipboard without modifying the font of my terminal.

Related

SQL BCP within Powershell hangs

I am new to BCP. I am tying to launch bcp.exe utility from Powershell but it hangs. Same command works fine command prompt. I am using Invoke-Expression to launch bcp.exe.
I am able to launch SQLCMD.exe without any problems.
This is my powershell.
Set-Location -Path "C:\Program Files\Microsoft SQL Server\110\Tools\Binn"
SQLCMD.EXE -b -E -S CORPSYSSQLDEV -d CORPSYSDM -Q "select top 10 * from t_test"
$psCommand = "bcp.exe ""testDB.dbo.t_test"" in ""C:\temp\test\testFile20180919.txt"" -c -t""\t"" -T -S ""TESTSQLDEV"" -e c:\temp\NoahFolder\error.csv"
Write-Host $psCommand
Invoke-Expression $psCommand
This is the result of $psCommand.
bcp.exe "testDB.dbo.t_test" in "C:\temp\test\testFile20180919.txt" -c -t"\t" -T -S "TESTSQLDEV" -e c:\temp\test\error.csv
Which works fine from command prompt but when I run the powershell script its stuck.
I am able to launch SQLCMD.exe from powershell fine.
What am I doing wrong? Any ideas or pointers.
I should have searched more before asking here. This post helped me. I was able to run BCP from powershell using Start-Process command.
$bcp = 'c:\Program Files\Microsoft SQL Server\110\Tools\Binn\bcp.exe'
$arglist = #(
#add all arguments.
)
Start-Process -FilePath $bcp -ArgumentList $arglist

AIX script hangs when using /dev/null > 2>&1

I am trying to run a script in AIX to execute another script on a remote server. In addition to the remote script i need to send the stdout to /dev/null. The same command works fine on another server but when I run on the current server it hangs, any advice?
su - test -c "rsh testserver /scripts/testme" 2>&1 >/dev/null1
In your comment you write that a menu is presented when the user logins.
Let's say this is done in the .profile file, using echoes and a read command.
When a menu is presented, the read command in the menu code will not be skipped by redirecting the output. The menu still waits for your input and the su command seems to hang.
Can you change your .profile or .bashrc so that it will skip presenting the menu when called using a su command? When this is called during startup, you can look at the returncode of tty. When you use the su command from the commandline, you should look for another solution.
When your root shell is ksh, you can try the following:
if [[ "$(ps -fp $$)" != *"-ksh -c "* ]]; then
echo "Now I should call the Menu"
fi

plink unable to execute the command with parameters

i could not able to execute the command with parameters in the plink.exe, when i provide the parameter command 'ls', it executes perfectly.
but if i provide command with parameters let's say 'ls -ltr', it say's commmand not found, this command executes perfectly in the unix command shell.
source code
c:\Gopal\putty>PLINK.exe -ssh gopc#hyperlvs03.qa.paypal.com -i c:\gopal\putty\gopc-private-key.ppk 'ls'
5036
BR-SWAT
CustomerOnBoardingEmailDataVO.oml~
GOPC.PG.conf
GOPC.PG.log
GOPC2.PG.conf
GOPC2.PG.log
GOPC2_PG.py
GOPC2_PG.pyc
GOPC_PG.py
GOPC_PG.pyc
GTest
Mail
\
afiedt.buf
color.sh
color.txt
compile.ksh
compile.ksh.bkup
error_log
file_backup_script.ksh
file_comp.txt
file_comp.txt_dev_BR_SWAT_38350
file_comp.txt_webdev_BR_SWAT_38350
file_not_found.txt
files_diff.txt
files_diff_compare.sh
gimp
gopc-0af4ba41-7528-20110810-211015190-cc_confirm.confirm_cc.vo.req.xml
i686
logs
mm-logs
mycommit
oradiag_UNKNOWN
oradiag_gopc
projects
public_html
scratch
scripts
stage.txt
tr
web.log
c:\Gopal\putty>PLINK.exe -ssh gopc#hyperlvs03.qa.paypal.com -i c:\gopal\putty\gopc-private-key.ppk 'ls -ltr'
bash: ls -ltr: command not found
please find the screen shot for the reference.

Execute remote powershell script from local system

I am new to this powershell..Execuse me if anything wrong here.
Now coming straight to the question I have a powershell script stored in one of the drive say "D:\myfile.ps1" which is in remote system.
Now I need to execute this script from my local system and this is the way I have done
ExecuteCommand(Directory.GetCurrentDirectory & "\Psexec \\myservername -i -u username -p password powershell.exe Invoke-Command -ComputerName \\myservername -FilePath D:\myscript.ps1")
The result is showing me this way without any output giving me an error
"powershell exited on myservername with error code 1'
And If run this script to run .exe on the same server it's working fine
ExecuteCommand(Directory.GetCurrentDirectory & "\psexec \\myservername -u username -p password D:\myfile.exe")
So what's the correct way to execute my script to run on remote desktop ?
Update after suggestions:
Can you just try :
ExecuteCommand(Directory.GetCurrentDirectory & "\Psexec \\myservername -i -u username -p password powershell.exe -command "&{Invoke-Command -ComputerName \\myservername -FilePath D:\myscript.ps1}"

tail -f using PuTTY hangs

I am using PuTTY command line to connect to a server and tail a log file. On local machine I've created a file "tail-exec" which contains following text:
tail -f /var/log/test.log
I am starting putty through command line as:
putty -ssh -t -pw -m tail-exec user#server
This opens up the terminal window with log tail. But the problem is that this terminal hangs after there are few hundred lines added to the log.
If I open putty manually, and then run the tail command from the bash prompt, then it is not hanging for thousands of lines also.
I've tried using following text in tail-exec file, but same issue is happening:
bash -i tail -f /var/log/test.log
Any idea what could be the issue?
Try to use a saved session where you set the Option "Keepalive". The use the session like this:
putty -ssh -t -pw -m tail-exec -load 'session-name'