output

Formatting issues / missing data when multiple commands use Select-Object within a script

混江龙づ霸主 提交于 2019-11-29 13:03:28
I've run into a problem with my PowerShell scripts where I am "losing" output that was going to the console, or being redirected. After much legwork, I simplified it down to an easily documented example of the problem. Place the following single line in a script (test1.ps1), and invoke it from a basic PowerShell command window: Get-WmiObject win32_share | select name, path and you will likely get two columns of output similar to the following: PS C:\Users\me\temp> ./test1.ps1 name path ---- ---- ADMIN$ C:\Windows C$ C:\ IPC$ Users C:\Users but now, create a two line script (test2.ps1) like

Python capture subprocess output after termination

走远了吗. 提交于 2019-11-29 11:53:22
I am trying to get subprocess output (on Windows) at the time the TimeoutExpired exception is raised. Any ideas? try: proc = subprocess.run(cmd,timeout=3) except subprocess.TimeoutExpired: print(???) You need to use Popen and subprocess.PIPE in order to catch the process output when timeout expires. In particular Popen.communicate is what you need. Here is an example proc = subprocess.Popen(["ping", "192.168.1.1"], stdout=subprocess.PIPE) try: output, error = proc.communicate(timeout=2) except subprocess.TimeoutExpired: proc.kill() output, error = proc.communicate() print(output) print(error)

Fortran 90 how to write very long output lines of different length

折月煮酒 提交于 2019-11-29 11:47:19
I've spent hours scouring the internet for a solution to this problem and can't find anything. I have been trying to write unformatted output to a CSV output file with multiple very long lines of varying length and multiple data types. I'm trying to first write a long header that indicates the variables that will be written below, separated by commas. Then on the lines below that, I am writing the values specified in the header. However, with sequential access, the long output lines are broken into multiple shorter lines, which is not what I was hoping for. I tried controlling the line length

Redirect stdout and stderr to the same file and restore it

有些话、适合烂在心里 提交于 2019-11-29 11:39:09
问题 I am redirecting the output of stderr and stdout of my c program to two files and then restoring the original stdout and stderr: int sout = dup(fileno(stdout)); freopen("test.txt","w",stdout); int serr = dup(fileno(stderr)); freopen("test.txt","a",stderr); //some output.... dup2(sout,fileno(stdout)); close(sout); dup2(serr,fileno(stderr)); close(serr); That's the code axample. This works. But I would like to redirect stdout and stderr to the same file(and later restore it again) so that the

count characters, words and lines in file

ⅰ亾dé卋堺 提交于 2019-11-29 08:58:10
This should count number of lines, words and characters into file. But it doesn't work. From output it shows only 0 . Code: public static void main(String[] args) throws IOException { int ch; boolean prev = true; //counters int charsCount = 0; int wordsCount = 0; int linesCount = 0; Scanner in = null; File selectedFile = null; JFileChooser chooser = new JFileChooser(); // choose file if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { selectedFile = chooser.getSelectedFile(); in = new Scanner(selectedFile); } // count the characters of the file till the end while(in.hasNext()) {

How to pipe all output of .exe execution in Powershell?

纵然是瞬间 提交于 2019-11-29 07:09:27
问题 In Powershell I am running psftp.exe which is PuTTy's homepage. I am doing this: $cmd = "psftp.exe" $args = '"username@ssh"@ftp.domain.com -b psftp.txt'; $output = & $cmd $args This works; and I am printing out $output . But it only catches some output in that variable (like "Remote working directory is [...]") and is throwing other output to an error type like this: psftp.exe : Using username "username@ssh". At C:\full_script.ps1:37 char:20 + $output = & <<<< $cmd $args + CategoryInfo :

How to execute a python script and write output to txt file?

微笑、不失礼 提交于 2019-11-29 06:45:51
I'm executing a .py file, which spits out a give string. This command works fine execfile ('file.py') But I want the output (in addition to it being shown in the shell) written into a text file. I tried this, but it's not working :( execfile ('file.py') > ('output.txt') All I get is this: tugsjs6555 False I guess "False" is referring to the output file not being successfully written :( Thanks for your help what your doing is checking the output of execfile('file.py') against the string 'output.txt' you can do what you want to do with subprocess #!/usr/bin/env python import subprocess with open

Python: fastest way to write pandas DataFrame to Excel on multiple sheets

核能气质少年 提交于 2019-11-29 06:41:31
I need to export 24 pandas data frames ( 140 columns x 400 rows) to Excel , each into a different sheet. I am using pandas’ built-in ExcelWriter . Running 24 scenarios, it takes: 51 seconds to write to an .xls file (using xlwt ) 86 seconds to write to an .xlsx file (using XlsxWriter ) 141 seconds to write to an .xlsm file (using openpyxl ) 21 seconds to just run the program (no Excel output) The problem with writing to .xls is that the spreadsheet contains no formatting styles, so if I open it in Excel, select a column, and click on the ‘comma’ button to format the numbers, it tells me: ‘style

How to open gnuplots in full screen and a particular size?

穿精又带淫゛_ 提交于 2019-11-29 06:14:43
I am plotting graphs in gnuplot and would like to open them in full screen and a particular size. Previously, I have been outputting graphs in multiplot mode and updating them using reread; so, when I maximise it manually, the plots fill the screen after a few iterations. Now, I also want to save the output as a file. When I open that file, it is in the same small size as the original multiplot output. However, when I maximise it, the plots don't increase in size to fill the screen. I have 2 questions: How can I open the multiplot file in full screen? How can I make the output file a

Cyrillic encoding output in R

丶灬走出姿态 提交于 2019-11-29 05:08:10
Encoding is always a pain for me, and again it's impossible to write file with russian text. What should I do for this? >test = c("привет","пока") >test [1] "\320\277\321\200\320\270\320\262\320\265\321\202" "\320\277\320\276\320\272\320\260" >Encoding(test) [1] "unknown" "unknown" > f = file("test.txt", encoding = "UTF-8") > write(t,f) Error in cat(list(...), file, sep, fill, labels, append) : argument 1 (type 'closure') cannot be handled by 'cat' > Encoding(test) = "UTF-8" > test [1] "<U+043F><U+0440><U+0438><U+0432><U+0435><U+0442>" "<U+043F><U+043E><U+043A><U+0430>" > write(t,f) Error in