Capture standard output of another command-line program, with characters not in current codepage
I'm using ProcessStartInfo.RedirectStandardOutput and Process.BeginOutputReadLine to capture the standard output of another program (specifically,
youtube-dl.exe) and save them into a string variable.
However the result variable contains only usual characters of my language such as traditional Chinese and English letters; characters such as Korean or Latin letters with accents simply vanished.
I File.WriteAllText-ed the result variable and checked the file using serveral text editors, so I'm sure they're lost, not that they exist and merely be un-display-able by console window.
Plainly executing youtube-dl in Windows Command Prompt displays complete messages including these foreign characters.
My youtubeDL_process.OutputDataReceived is simply:
(s, e) => { if(!string.IsNullOrWhiteSpace(e.Data)) this._filename = e.Data; }
How to make the redirected standard output string with foreign characters complete, just like one directly generated in a command prompt?
Try a different experiment of starting your second EXE:
string exe =
@"path to your EXE with arguments . . .";
Process p =
new
Process
StartInfo =
UseShellExecute = false,
RedirectStandardOutput = true,
StandardOutputEncoding = Encoding.UTF8,
FileName = "cmd.exe",
Arguments = "/C chcp 65001 > null && " + exe
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Specify the full path in the exe variable, using quotation marks if it contains spaces.
Then check the value of output.
Similar Messages
-
Cope: a command-line program colouriser
cope is a wrapper around various command-line programs that takes their output and adds colours - a sort of ornamental cope, if you will.
It's written in Perl, and requires version >= 5.10, so installation may be a bit complicated if you have to track down the dependencies. It installs several scripts in a directory, each one calling the program it's named after, only highlighting its output using regexes. Then you add this directory to your $PATH, and everything should (hopefully!) be seamless.
Currently it's in release candidate status - I've been using it personally for a few weeks and nothing catastrophic has happened so far, so there's little point me keeping it private.
Screenshots:
Main site: http://stuff.cytzol.org/cope/
GitHub: http://github.com/cytzol/copePKGBUILD
# Contributor: denton <e9203.00 gmail com>
pkgname=cope-git
pkgver=20091208
pkgrel=1
pkgdesc='A colourful wrapper for terminal programs'
arch=(any)
url=http://stuff.cytzol.org/cope/
license=('GPL' 'PerlArtistic')
depends=("perl>=5.10")
makedepends=(git)
provides=(cope)
conflicts=(cope)
install=$pkgname.install
_gitroot=git://github.com/cytzol/cope.git
_gitname=cope
build() {
cd $srcdir
# Git
msg 'Connecting to Git server...'
if [ -d $_gitname ] ; then
cd $_gitname && git pull origin || return 1
msg 'The local files are updated.'
else
git clone $_gitroot || return 1
fi
msg 'Git checkout done or server timeout.'
msg 'Starting make...'
rm -rf $srcdir/$_gitname-build
git clone $srcdir/$_gitname $srcdir/$_gitname-build || return 1
cd $srcdir/$_gitname-build
# Build
PERL_MM_USE_DEFAULT=1 perl Makefile.PL INSTALLDIRS=vendor || return 1
make || return 1
make install DESTDIR=$pkgdir || return 1
# Remove perllocal.pod and .packlist
find $pkgdir -name perllocal.pod -delete
find $pkgdir -name .packlist -delete
cope-git.install
post_install() {
echo 'Prepend /usr/share/perl5/vendor_perl/auto/share/dist/Cope/ to $PATH'
post_upgrade() {
post_install
First time making a perl package. It puts files that shouldn't be in */site:
/usr/bin/perlbin/site/envpath
/usr/lib/perl5/site_perl/5.10.1/IO/Pty.pm
/usr/lib/perl5/site_perl/5.10.1/IO/Tty.pm
/usr/lib/perl5/site_perl/5.10.1/IO/Tty/
/usr/lib/perl5/site_perl/5.10.1/IO/Tty/Constant.pm
/usr/lib/perl5/site_perl/5.10.1/List/MoreUtils.pm
/usr/lib/perl5/site_perl/5.10.1/Params/Util.pm
/usr/lib/perl5/site_perl/5.10.1/auto/IO/Tty/Tty.bs
/usr/lib/perl5/site_perl/5.10.1/auto/IO/Tty/Tty.so
/usr/lib/perl5/site_perl/5.10.1/auto/List/MoreUtils/MoreUtils.bs
/usr/lib/perl5/site_perl/5.10.1/auto/List/MoreUtils/MoreUtils.so
/usr/lib/perl5/site_perl/5.10.1/auto/Params/Util/Util.bs
/usr/lib/perl5/site_perl/5.10.1/auto/Params/Util/Util.so
/usr/share/perl5/site_perl/5.10.1/Class/Inspector.pm
/usr/share/perl5/site_perl/5.10.1/Class/Inspector/
/usr/share/perl5/site_perl/5.10.1/Class/Inspector/Functions.pm
/usr/share/perl5/site_perl/5.10.1/Env/Path.pm
/usr/share/perl5/site_perl/5.10.1/IO/Stty.pm
/usr/share/perl5/site_perl/5.10.1/IO/stty.pl
/usr/share/perl5/site_perl/5.10.1/Regexp/Common.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/CC.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/SEN.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/RFC1035.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/RFC1738.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/RFC1808.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/RFC2384.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/RFC2396.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/RFC2806.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/fax.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/file.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/ftp.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/gopher.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/http.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/news.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/pop.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/prospero.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/tel.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/telnet.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/tv.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/URI/wais.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/_support.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/balanced.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/comment.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/delimited.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/lingua.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/list.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/net.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/number.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/profanity.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/whitespace.pm
/usr/share/perl5/site_perl/5.10.1/Regexp/Common/zip.pm
And as shown by the previous list, I haven't fetched these binaries (are they in the repos?):
Env::Path
File::ShareDir
IO::Handle
IO::Pty
IO::Stty
List::MoreUtils
Regexp::Common
Term::ANSIColor
Everything works, except cope_path.pl.
Last edited by denton (2009-12-08 09:14:37) -
Uninstalling Command Line Programs
I've searched these forums and the internet for an answer to this, but there doesn't seem to be anything out there, so I hope this will be helpful to others as well.
I have some open source command line programs that I downloaded, compiled, and installed as part of some exercises I was doing in a book on open source GIS (geographic information systems). What I want to know is how do I remove those programs? I can find references for compiling and installing these types of programs all over the internet, but nothing about removing or uninstalling them.
Also, any ideas for good, up-to-date references on learning Unix in Mac OS X would be appreciated too. I'd like to get more into open source GIS, but from the research I've been doing, knowing Unix would help a lot.What process did you use to compile and install? Was it a configure, make, make install sequence, which is fairly common? If so, go back to the directory where you did that, and try, for example, 'make uninstall'. This might work.
Look for output files from the compile and install process (perhaps config.log) that might tell you where files will be installed. Perhaps in /usr/local?
Is there a README or INSTALL file that came with the source code? Documentation about what was installed where might be there.
If worst comes to worst, and you're really determined, you could repeat the compile and install steps, but with a before and after listing of all the files in your system, and compare the listings. Or use the find command immediately after the reinstall, looking for recently created or changed files (the 'mtime' option or similar). -
Creating a command line program reading AEP/AEPX files?
I'm new with After Effects SDK, and I wanted to know if it's possible to use SDK to implement a command line program that gets information such as duration and frame rate in AEP/AEPX files.
aerender, a command line render program provided by After Effects, prints out these information before rendering. But it doesn't seem to be able to print out the information without doing rendering.
I saw a related thread here: http://forums.adobe.com/thread/844341
But what I want is simpler. I don't need to alter the AEP/AEPX files. I just want to obtain the information quickly from an AEP/AEPX file. Is it possible to write such a tool using SDK?
Thanks!hi eliang.cs!
yes, i'm the same guy who answered on the other thread.
everything the API does, it does through AE as a plug-in.
so if you have AE running (even just the renderer), your project loaded and your plug-in present, you can access all the data you described with no problem, and export it out in whatever way you want. (a plug-in is actually a DLL, so you can do anything you want, even on an OS level)
you can access the data on all elements of the project including comps, layers, footage, render queue, ect...
having said that, you can do all of this using a script instead of a plug-in.
scripts are much easier to build.
perhaps there's even a script out there that does what you're looking for, or something very close that could easily be adjusted. -
Is there a command line program that converts WAV to SWF?
Is there a command line program that converts WAV to SWF?
thankswhy you want to do that? you can import your wav into the
swf! -
Fast command-line program which displays connectivity
Hi
I'm looking for a command-line program which can show whether or not my network interface has an IP address or not. It could use "ifconfig" to extract the information, I don't really care, but it has to be *fast* and it cannot require root access.
ThanksThanks, but if someone knows some sed/awk magic to get only the interface's IP address, that would be great!
EDIT:
Using the little "sed" I know, this is what I came up with:
ifconfig wlan0 | grep -w inet | sed "s/^\\s*//" | sed "s/^inet addr://" | sed "s/\\s.*//"
EDIT2:
Now I have this reasonable command:
ifconfig wlan0 | grep -w inet | sed "s/.*inet addr:\([^ ]*\).*.*/\1/"
Last edited by skorpan (2009-06-07 16:44:19) -
Tagging command line programs in subtle?
I'd like to be able to tag command line programs so I can assign them to specific views and gravities within those views.
For example, I'd like to be able to have 'gclacli calm' be recognized by a tag so it appears in my 'agenda' view and assign it a gravity. Is there a way to do this? Right now the best I can do is limit xterm to different views but they still move around when I change views.
Last edited by tinySpark (2012-06-14 18:04:12)None of these options have worked.
for the user variables, i just create a new one called "Path" and type in my path to java \bin right?
This is quite frustrating. Thanks for the help though!
--Brenton -
WLST command line utility "storeUserConfig()" is not working for 12c OHS
Hi All,
I am facing issue with WLST command line utility with "*storeUserConfig()*" command.
I have installed Standalone OHS 12c (Not managed OHS with WLS), configure and start the Node Manager.
I start the WLST command line utility from : <MW_HOME>/ohs/common/bin/wlst.sh
I connect node manager with : nmConnect('weblogic', 'welcome1', nmType='plain', domainName='base_domain')
wls:/offline> nmConnect('weblogic', 'welcome1', nmType='plain', domainName='base_domain')
Connecting to Node Manager ...
Successfully Connected to Node Manager.
wls:/nm/base_domain> nmStart(serverName='ohs10', serverType='OHS')
Starting server ohs10 ...
Successfully started server ohs10 ...
Now When I am running storeUserConfig(), it's giving me below error :
wls:/nm/base_domain> storeUserConfig()
Traceback (innermost last):
File "<console>", line 1, in ?
NameError: storeUserConfig
I also try with storeUserConfig('/scratch/12cORC/security/myuserconfigfile.secure', '/scratch/12cORC/security/myuserkeyfile.secure') which also give same error.
I am not able to recognize this error. What should I need to do to create the User config file ?
Please suggest me the solution.
I am referring this doc : http://docs.oracle.com/cd/E15586_01/web.1111/e13813/reference.htm#
Thanks,
Amit NagarIt's probably a little late for the original poster, but in case anybody else stumbles on this thread (like me today), I found a workable solution to this problem:
For a Standalone HTTP Server there exists in $domain_home/bin a command startComponent.sh or (on Windows) startComponent.cmd. This accepts as parameter the ComponentName which will typically be ohs1 and as second parameter storeUserConfig. Documentation on this can be found here:
http://docs.oracle.com/middleware/1212/webtier/HSADM/getstart.htm#CHDJGIII (scroll down to
4.3.2.3 Starting Oracle HTTP Server Instances from the Command Line).
startComponent.sh ohs1 storeUserConfig
Unfortunately this doesn't tell you where you'll find the config and key-File. However, on a second invocation I found that - at least on windows where I tested this - they get written into c:\users\<username>\.wlst so I'd expect them in the home directory on unix. After copying the files to a more common location, I was able to reference them the usual way (formatted for better readability):
wls:/offline> nmConnect(userConfigFile='C:/app/Middleware/Oracle_Home/user_projects/domains/base_domain/nodemanager/security/nm-cfg-base_domain.props',
userKeyFile='C:/app/Middleware/Oracle_Home/user_projects/domains/base_domain/nodemanager/security/nm-key-base_domain.props',
host='localhost',
port='5556',
domainName='base_domain')
Connecting to Node Manager ...
Successfully Connected to Node Manager.
Best Regards
Holger -
Command line authentication "/ap" is not working on the Mac
I am trying to connect to my media server using the Mac version of FMLE, but my server has authentication and I cannot connect to it using the command line. I use the /ap command line option with the username:password string, it works on Windows, but not on the Mac.
Do anyone else have this problem? If someone made it work somehow using command line authentication, could you please tell me how you made it work? Thank you.It's working for me.
Are you using the right credentials? What's the error fmle gives? -
Variant NLFRS1 of program RFSSLD00 is not the current version
Hi,
I am getting a error message "Variant NLFRS1 of program RFSSLD00 is not the current version" when I tried to display the variant
Help me to solve the issue?
Thanks & Regards
Suresh KumarMahesh,
One more thing to add, if the variant is changed purposefully,
Go to
SE38
For the Program,
1. select the variant 'RADIO BUTTON'
2. Click 'Display'.
3. On the Menu, Click 'Variants'.
4. Click on 'Adjust'.
5. Now, Click the 'Execute' button.
Execute the Program with the Variant now.
This should resolve the isssue. -
How to capture the output of another program into a File/String
I needed to capture the output of a dos program in an String/file I tried doing Runtime.getRuntime.exec("ipconfig /all >tmp.txt");
but still I am unable to capture the output frm the program which I would like to capture in a file or String.Can anyone helpWhen you use the Runtime.exec() method, it returns a Process object, that process object has access to the streams; stdout, stdin, and stderr of the application you just executed. what you'll want to monitor is the stdout or stderr streams using the
p.getInputStream() or p.getErrorStream(), where p = the process object returned via the Runtime.exe() method. -
Open file in folder with command line program
I have a file, which is in native format for a given program [1] I have installed. This program I can start from Terminal.app and within the program I can open the file. The question is if I can have associated with this specific filetype this program and when I double click on a file of this type I can have a Terminal.app opened with my program running inside opening the file for me.
Btw, on a regular Linux/Unix I would just associate this filetype with the path to my program. On Mac I can associate only with .app.. Is there other way?
[1] http://root.cern.ch/drupal/I do not fully understand your question.
You need to make your program into an application. I have not programmed on Mac OS so I to not know the details. You could hack some existing app. I do know that the plist file for an app points to the starting program.
Another work around would be to write an apple script file to call your program.
This applescript invokes a unix program.
Run in the Script Editor.
Click on the Event Log tab to see the output from the log statement
Click on Run
For running shell commands see:
http://developer.apple.com/mac/library/technotes/tn2002/tn2065.html
on run
-- Write a message into the event log.
log " --- Starting on " & ((current date) as string) & " --- "
-- ask the user for the folder name.
-- quoted form of (POSIX path of (choose folder))
set theFolder to "/Applications/Utilities/Disk Utility.app"
set theFolder to quoted form of theFolder
log "quoted form is " & theFolder
-- running two Unix commands. Separate with a semicolon
set fromUnix to do shell script "cd " & theFolder & "; ls -ld ."
log fromUnix
display dialog fromUnix giving up after 30
end run
This applescript program received a file dropped on it.
There is a lot of extra stuff but look at on open dropped_items This line gets a list of files dropped on the applescript. Your have to change the name format.
on open dropped_items
-- Remember you need to turn on enable assistive devices
-- this lets applications software to access screen elements
-- blue apple > system perferences > universal access > enable assistive devices
-- Write a message into the event log.
log " --- Starting on " & ((current date) as string) & " --- "
-- set see to alias "Macintosh-HD:Users:mac:Desktop:app.html"
-- set dropped_items to {see}
set the_app to "Safari"
repeat with dropped_item_ref in dropped_items
--set UrlBase to "xzzx FILE://" & POSIX path of dropped_item_ref
--display dialog UrlBase
-- Activate
activate application the_app
-- Open the URL
tell application the_app
open dropped_item_ref
-- print dropped_item_ref
tell application "System Events"
tell process the_app
delay 3
-- click menu item "Print..." of menu "File" of menu bar 1
keystroke "p" using command down
delay 1
keystroke return
delay 10
keystroke "w" using command down
end tell
end tell
--quit
end tell
end repeat
end open -
Java command line programming in windows
Here's what I want to do:
-write .java files in a text editor
-compile and run them from a command line, rather than using a
compiler like codewarrior or MS J++
Here's my problem:
In a program that produces output, I can't seem to find a way to
retain the output that goes off the screen in a DOS window. Is there
a way to enable scrolling in a DOS window, or are there any
alternative command line terminals for Windows? Any suggestions
would be greatly appreciated.I think you can increase the Screen Buffer size which should give you a scroll bar. For this right click on the icon on the top left of the DOS window -select Properties - Go to Layout tab.
Another option will be to redirect the output to a file
java SomeClass > log.txt
Hope this helps. -
Problem executing command line program
Hi I have a tuxedo command line app in Solaris 2.6. I was able to execute the program from unix prompt however when I try to do it from JAVA program, it does not work.
I have to execute from command line as follows
$ud32<SPACE>-U<SPACE>login<nl>
SRVCNM<TAB>CB_EXESUB<nl>
CLFY_SUB<TAB>ExeternalMsg<nl>
EQUIP_ID<TAB>1<nl>
<nl>
during command line execution from second line on you will not get the prompt. After entering a balnk line the program will execute and provide the output.
I was aslo able to execute the program by putting the last 4 lines in a file(say test.bat) and executing by issuing following command at the unix prompt
$ud32 -U sa<test.bat
My java program as follows.
import java.io.*;
public class udexec {
public static void main(String args[]) {
try{
Runtime rt = Runtime.getRuntime();
System.out.println("Before");
Process prcs = rt.exec("ud32 -U sa");
System.out.println("After: " + prcs);
InputStreamReader isr = new InputStreamReader(prcs.getInputStream());
PrintWriter out = new PrintWriter(prcs.getOutputStream());
out.println("SRVCNM CB_EXESUB");
out.println("CLFY_SUB ExternalMsg");
out.println("EQUIPID 1");
out.println("");
int ret = isr.read();
String line;
System.out.println("Before Print");
System.out.println(ret);
catch (Exception e) { System.out.println(e); }
Any help will be greatly appreciated.
Thank You
RajuHmm, maybe you should also give additional Excape Characters to the Process (so adding \t where you have written <TAB>, or adding \r to the lines).
-
Setting column width in a command-line program
Is there a way to send data to the screen in a command-line Java program that will be formatted as a number
of columns with a set column width? I am looking for something similar to the C++ setw() I/O manipulator
used in cout.
Thanks,
SteveIf you go to: http://java.sun.com/docs/books/tutorial/essential/io/writingFiltered.html
it will show you how to subclass a filtered output stream and add your own formatting methods.Then you can chain your new class to System.out
like this:
YourFilteredStream yfs = new YourFilteredStream(System.out); .
Then:
yfs.yourNewMethod(); goes directly to system out in the new format.
Maybe you are looking for
-
Add fields in the BW extraction structure
Dear Experts: Today I have added a field "UEPOS" in the BW extraction struction MC11VA0ITM. UEPOS is the standard field of the SAP TABLE VBAP. When I test the extraction of the new field the system did not move the corresponding value from VBAP
-
Adobe update process fails due to Error 130200. solutions please
adobe update process fails due to Error 130200. solutions please. Shyam
-
Nothing else to tell. Just can't download 4.0. Goes along fine to the very end, stops abruptly before completing. I expected to see a FireFox screen indicating a complete download and instructing a restart, but just got the little window at the botto
-
After updating to the latest version of Firefox all the themes under addons have simply disappeared, and when I click get addons the page goes into perpetual load, with the little loading circle swirling away. The themes page never loads...
-
how to configure sql mail server 2008 for 64bit machine