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 help
When 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.
Similar Messages
-
How to write the output of a mapping into a file (OWB10.2
Hi
I am using Oracle 10.2.0.1 version of OWB.
the task is to write the output of a mapping into a File (Flat File).
Please help me out!
Regards
AbiHi,
Create the file format thru OWB and mention the location in OWB. Deploy the file and it will be ready to use for target load. Make sure the connection to the target loc is available.
Regards
Bharadwaj Hari -
How to get the output of a program into the email program.
hi
i had created a java mail program and the keygeneration program.seperately.
i want to get the keygeneration into my email program.that should be sent along with the text message.so pls help me in this regared.
i had pasted my coding her
email pgm.
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.io.*;
To use this program, change values for the following three constants,
SMTP_HOST_NAME -- Has your SMTP Host Name
SMTP_AUTH_USER -- Has your SMTP Authentication UserName
SMTP_AUTH_PWD -- Has your SMTP Authentication Password
Next change values for fields
emailMsgTxt -- Message Text for the Email
emailSubjectTxt -- Subject for email
emailFromAddress -- Email Address whose name will appears as "from" address
Next change value for "emailList".
This String array has List of all Email Addresses to Email Email needs to be sent to.
Next to run the program, execute it as follows,
SendMailUsingAuthentication authProg = new SendMailUsingAuthentication();
public class SendMailUsingAuthentication
private static final String SMTP_HOST_NAME = "smtp.mail.yahoo.com";
private static final String SMTP_AUTH_USER = "xxxx";
private static final String SMTP_AUTH_PWD = "xxxx";
//private static final String emailMsgTxt = "Online Order Confirmation Message. Also include the Tracking Number.";
private static final String emailSubjectTxt = "Order Confirmation Subject";
private static final String emailFromAddress = "[email protected]";
private static String emailMsgTxt = "I am unable to attend to your message, as I am busy sunning"
+ "myself on the beach in Maui, where it is warm and peaceful."
+ "Perhaps when I return I'll get around to reading your mail."
+ "Or perhaps not.";
private static final String[] emailList = { "[email protected]","[email protected]"};
public static void main(String args[]) throws Exception
SendMailUsingAuthentication smtpMailSender = new SendMailUsingAuthentication();
smtpMailSender.postMail( emailList, emailSubjectTxt, emailMsgTxt, emailFromAddress);
System.out.println("Sucessfully Sent mail to All Users");
public void postMail( String recipients[ ], String subject,
String message , String from) throws MessagingException
boolean debug = true;
Properties props = new Properties();
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "25");
props.put("mail.smtp.protocol","smtp");
props.put("mail.debug", "true");
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getDefaultInstance(props, auth);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
addressTo[i] = new InternetAddress(recipients);
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
private class SMTPAuthenticator extends javax.mail.Authenticator
public PasswordAuthentication getPasswordAuthentication()
String username = SMTP_AUTH_USER;
String password = SMTP_AUTH_PWD;
return new PasswordAuthentication(username, password);
keygeneration program:
import java.io.Serializable;
import java.security.Security;
import com.sun.net.ssl.*;
import javax.crypto.KeyGenerator;
import javax.crypto.Mac;
import javax.crypto.SecretKey;
public class Eval {
public static void main(String args[]) throws Exception {
String inputString ="0x0b0b0b0b";
KeyGenerator keyGen = KeyGenerator.getInstance("HMACMD5");
SecretKey secretKey = keyGen.generateKey();
Mac mac = Mac.getInstance(secretKey.getAlgorithm());
mac.init(secretKey);
byte[] byteData = inputString.getBytes("UTF8");
byte[] macBytes = mac.doFinal(byteData);
String macAsString = new sun.misc.BASE64Encoder().encode(macBytes);
System.out.println("Authentication code is: " + macAsString);I'm not sure what's confusing you. Just generate a String (using a StringBuffer)
with the data you need and use it as the content of the mail message. If each
recipient needs different content, they'll each need a different MimeMessage
object. -
Passing the output to another program
Passing the output to another program
The problem I have that I don�t know how to pass the results of my java Program ( as parameter) to another application!
I have a class �A.class� should send result �VAR_result� to application �B.application�
Now I am using it like this: System.out (VAR_result) >> B.application
But it could not be the right way at least because I cant make any other System.out as debug now.
My Question please: to pass a parameter to a java is clear: A.class ( var ..)
But how to take a parameter from a class, to use it in another Applicatin ( script )?
Thanks a lotslackware2007 wrote:
Passing the output to another program
The problem I have that I don’t know how to pass the results of my java Program ( as parameter) to another application!
I have a class “A.class” should send result “VAR_result” to application “B.application”
Now I am using it like this: System.out (VAR_result) >> B.application
But it could not be the right way at least because I cant make any other System.out as debug now.Then move your debug to System.err and use System.out as it should be used and pipe stdout to the stdin of the other application.. -
Procedure to save the output of a query into excel file or flat file
Procedure to save the output of a query into excel file or flat file
I want to store the output of my query into a file and then export it from sql server management studio to a desired location using stored procedure.
I have run the query --
DECLARE @cmd VARCHAR(255)
SET @cmd = 'bcp "select * from dbo.test1" queryout "D:\testing2.xlsx;" -U "user-PC\user" -P "" -c '
Exec xp_cmdshell @cmd
error message--
SQLState = 28000, NativeError = 18456
Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'user-PC\user'.
NULL
Goel.AmanHello,
-T:
Specifies that the bcp utility connects to SQL Server with a trusted connection using integrated security. The security credentials of the network user,
login_id, and password are not required. If
–T is not specified, you need to specify
–U and –P to successfully log in.
-U:
Specifies the login ID used to connect to SQL Server.
Note: When the bcp utility is connecting to SQL Server with a trusted connection using integrated security, use the
-T option (trusted connection) instead of the
user name and password combination
I would suggest you take a look at the following article:
bcp Utility: http://technet.microsoft.com/en-us/library/ms162802.aspx
A similar thread regarding this issue:
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/b450937f-0ef5-427a-ae3b-115335c0d83c/bcp-connection-error-sqlstate-28000-nativeerror-18456?forum=sqldataaccess
Regards,
Elvis Long
TechNet Community Support -
How to capture graphical outputs from other programs
Does anyone know how we capture the graphical outputs from the other programs and show them
on the swing?
I'd like to use a java program to run gnuplot, capture the outputs, and show them using swing.Depends on what you mean by "graphic outputs".
Taking a quick glance at the gnuplot homepage, it looks as if you can output to PNG files, so just run the app, and load the png file. -
How to export the Screens of dialog programming into notepad
Hi Guys,
Here I am having a requirement to copy the screens of dialog program into another SAP system.
So I have to export the screen along with coding into NOTEPAD.
I am able to copy the coding part, <b>but how to copy the screen into notepad</b>
Give me the appropriate answers.
I will award the points to the answersHi Chakra.
please take carte that a screen consists of layout, fields and flow logic. Get all components using this form routine (taken from excellent useful SAP report RPR_ABAP_SOURCE_SCAN):
Form GET_DYNPRO_FLOW_LOGIC
Get flow logic of the dynpro
form get_dynpro_flow_logic.
data: dhead like d020s,
dfield like d021s occurs 0,
dflow like d022s occurs 0,
dmatch like d023s occurs 0,
begin of dynp_id,
prog like d020s-prog,
dnum like d020s-dnum,
end of dynp_id.
dynp_id-prog = dyn-prog.
dynp_id-dnum = dyn-dnum.
import dynpro dhead dfield dflow dmatch id dynp_id.
rtab[] = dflow[].
endform. " GET_DYNPRO_FLOW_LOGIC
Regards,
Clemens -
How to capture the user who has logged into the portal.
Hi,
How do I capture the user who has logged into the portal.
HOw do I retrieve the first name and last name of the logged in username.
Could someone provide me a related link or PDF to work on this.
Thanks,
SuvarnaHi suvarna,
Check the following code
ISearchResult rst = UMFactory.getUserFactory().getUniqueIDs();
IUserFactory usf = UMFactory.getUserFactory();
IUser iuser = null;
IUserListElement userElement = null;
int i = 0;
while (rst.hasNext()) {
iuser =
UMFactory.getUserFactory().getUser(rst.next().toString());
String email = iuser.getEmail();
String fname = iuser.getFirstName();
String lname = iuser.getLastName();
regards
Anil Dichpally -
Reading the output from another program.
I haven't used Java in a good long while so I need someone to point me in the right direction. I have a C program that I call from a command line (windoze boxen) and it spits out some neat data. I can call it from inside a Java program, but how do I then read the output from the calling Java program? I'd just alter the C program, but I lost the source.
This article explains how to correctly execute another program from your
Java program, and read its output:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html -
How to save the output of report program??
Hello Everbody,
I want to save the output of a report program(i.e list),how can i do this???which function module should i use to achieve this???
Thanx in advance.<b>data: list like abaplist occurs 0 with header line.
data: begin of listout occurs 0,
line(1024) type c,
end of listout.
do 100 times.
write:/ sy-index.enddo.
call function 'SAVE_LIST'
EXPORTING*
LIST_INDEX = '0'
tables
listobject = list
exceptions
list_index_invalid = 1
others = 2 .
call function 'LIST_TO_ASCI'
tables
listobject = list
listasci = listout
exceptions
empty_list = 1
list_index_invalid = 2
others = 3.
call function 'GUI_DOWNLOAD'
exporting
filename = 'C:\Test.txt'
tables
data_tab = listout.</b> -
How to invoke the compiler from another program
Hi guys,
Suppose I have a source code located in the file MyClass.java.
Now suppose I'm running another program, and in this program I want to compile the MyClass.java file and create the MyClass.class file. Is there a way of doing it through the standard API?
Thanks.I believe Java 1.6 has a Compiler class as a part of it's "standard" API. Before that, you've got a package called tools.jar in your SDK directory, which is a Java gateway to the compiler
-
How to spool the result of an query into a file in sql 2000
Hi All,
I have an SQL query which iterates through number of times for checking on some conditions and will return results each time. I wants to save the results into an different xml file each time. I tried using below query:
exec xp_cmdshell 'bcp "use Mimsadaptorlogs; select top 10 * from log order by logdate" queryout "D:\cdr_cg.xml" -T -c -t,' ---> Its not working as expected.
I got the Below output:
NULL
Starting copy...
SQLState = 01000, NativeError = 5701
Warning = [Microsoft][ODBC SQL Server Driver][SQL Server]Changed database context to 'MIMSAdaptorlogs'.
NULL
10 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.): total 62
NULL
Could you anuone please suggest me on this.......
Thanks and Regards, BalaYou will need to write a client program to do this. SQL Server is not intended for writing files. People still do it by calling BCP through xp_cmdshell, but this is a dubious practice. Better is to write a CLR stored procedure for the task. However, you
are on SQL 2000, and the CLR support was added in SQL 2005. Furthermore, there is no XML type in SQL 2000, and the only way to generate XML is with the FOR XML clause. But this output is not well understood by BCP. Then I try: [code} bcp "SELECT * FROM Northwind..Customers
FOR XML RAW" queryout slask.bcp -c -T [/code] on SQL 2000, I get [code] 11 rows copied. [/code] which is complete hogwash, because there are 91 rows in that table, and the output should be a single XML document, and the output looks like this: [code] <row
CustomerID="ALFKI"... Bouchers" City="Marseil... tomerID="DUMON" Company... 0.32.21.21" Fax="40.32.... los Hern ndez" ContactT... n Steel" ContactTitle="... e" ContactTitle="Market... ="Salzburg" PostalCode=... " Phone="(21) 555-3412"... ty="Charleroi" PostalCo...
<row CustomerID="WARTH"... [/code] I have truncated the output on the right side, but the left side is authentic. It really is that bad.
Erland Sommarskog, SQL Server MVP, [email protected] -
Capturing the output of a jsp page and save that output in a WORD .doc file
Hi,
This is Naveen. I got stuck up with a problem/doubt. URGENT ! URGENT !
My doubt is how to capture the output of a jsp page(the content is dynamic generated) and save that output to a MS-Word doc file.
I know that therez an option of using Servlets Filters, but this concept is supported by Servlet 2.3 spec. and not earlier. And we are working on previous spec. and our web-servers also supports the prev. version and not the 2.3 version.
If incase, therez a third-party utility for free usage, suggestions are appreciated.
Hope most of them came across this kind of functional requirement. If anyone of them succeeded in this, please express ur bitter experience if any, faced during the coding.
Thanks in Advance for help.
NaveenYou can set the MIME content type as .doc and try to open the Page.
res.setContentType("application/vnd.ms-excel"); to generate the Page output as Excel
res.setContentType("application/vnd.ms-word"); to generate the Page output as MS Word doc
Hope this helps.. -
Capture the output of ExceptionDescribe
I have some C++ code which calls Java code through the Invocation API:
jType type = env->SomeJNICall();
if ( type == NULL || env->ExceptionOccurred() )
env->ExceptionDescribe();Instead of spitting out the exception description to stdout (or stderr?) is there a way of capturing the text and putting it into a std::string or copying it into a memory location pointed to by a char *?
Thanks!I believe the API can be used to return the actual exception. With that, you can get its class, and with its class you can call methods of the exception object. (All, of course, via JNI.)
-
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.
Maybe you are looking for
-
Dear All, I have a scenario in which messages from XI have successfully processed but are still in queue in P00 side. They have not failed or anything just that the first message in queue is of large size so it will take time to process. Is there any
-
Hi, i suddenly have problem with the display. Its gone very dark and only sometimes flickers up to the normal brightness. I cant get it bright anymore. Its only a year old. Any idea what can be done?
-
Google Toolber does not work with Firefox 4
I just downloaded Firefox 4 and Google Toolbar does not work. I removed and re-downloaded it and it still does not work. I can't even uninstall via the wrench. Is there a version of toolbar that works with Firefox 4?
-
why did not i get installation CD with my mac book retina display 13", when i bought. and let me know what are the tings i get with my mac book pro with free of cost?
-
Help trying to figure out which devise to use
have used tungsten for years. want a phone and pda combo for business app. the ones i tried in the sprint store will not open my quickbooks online web pages. is there somthing that needs to be added? i am not a teckie but would like the freedom of do