I need to call a java program and pass parameters from C#
I'm new to C# and was given a project to rewrite some of my old VB.net programs to C# to help me learn. These VB programs call quite a few .bat files that have calls to java programs in them. I'm doing okay converting my VB code, but I've been
stumped for days trying to figure out how to call java from C#.
Does anyone here know how to do this? I really should've had this figured out by now and my back is to the wall. Ugh :(
This is the line from the .bat file that I need to convert to C#.
call jvbat production_r115.Automotive m:\data\MK115mn.100 m:\data\MK115mn.101 %6
There is one parameters being passed, %6
I would be forever grateful if someone can show me how to do this!
Hi Joni,
Do you mean call a bat file that it is a Java program from C#? If so, there is an article talking about it.
If that's not what you're trying to do, please be more specific about what you're trying to do.
http://www.c-sharpcorner.com/UploadFile/maheswararao/CallingJavaProgramfromCS12062005233321PM/CallingJavaProgramfromCS.aspx
Now the next issue is pass some parameters from C#.
The above article tells using Process.Start() method to call java program. Also in this class, you could specify them all in the
Arguments property:
var p = new Process();
p.StartInfo.Arguments = string.Format("{0} {1}", argument1, argument2);
For more detailed information, please refer to
C# Passing Multiple Arguments to BAT File
Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control
these sites and has not tested any software or information found on these sites;
Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information
found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.
Best regards,
Kristin
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.
Similar Messages
-
Executing a program and passing parameters using ProcessStartInfo
I am trying to run an application and pass parameters from within a c# desktop application. It appears to attempt to execute but it doesn’t run and the exeProcess shows errors in the locals.
Here is the code:
ProcessStartInfo startBin2TextApp =
new
ProcessStartInfo(strNowRunThis, strDataFile +
" a");
startBin2TextApp.CreateNoWindow =
true;
startBin2TextApp.UseShellExecute =
false; startBin2TextApp.WindowStyle =
ProcessWindowStyle.Hidden;
Process exeProcess =
null;
exeProcess = Process.Start(startBin2TextApp);
This is what is in the Arguments when Process.Start(startBin2TextApp) is ready to execute.
Arguments "C:\\Users\\10065421\\Documents\\ab\\Working\\Projects\\Panel Explorer\\B640130A.DAT a"
After the line is executed, exeProcess shows an error in most of the attributes. For instance, BasePriority shows “exeProcess.BaePriority” threw an exception of type “System.InvalidOperationException”.
I ran this from the command prompt so I know it runs on this machine with the same parameters I am using in the code.
Any ideas?
Thanks.Here is the complete code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using System.Threading.Tasks;
namespace PanelExplorerV1
public
class
CommonCode
public
delegate
void
PassStatusBackFunction(string
msg);
public
void RunBinToText(PassStatusBackFunction
messageCallback)
try
string strStartDirectory =
string strDataPath =
string strDataFile =
string strDataFileTitle =
string strBin2TextPath =
string strDestinationDirectory;
string strNowRunThis =
//int intReturnValue = 0;
strStartDirectory =
Application.StartupPath;
OpenFileDialog dlgCommonDialog =
new
OpenFileDialog();
//CommonDialog dlgCommonDiaglog = new CommonDialog();
dlgCommonDialog.FileName =
//dlgCommonDialog.CancelError = true;
dlgCommonDialog.Filter =
"Binary Data Files (*.dat)|*.dat|All Files (*.*)|*.*";
dlgCommonDialog.ShowDialog();
strDataFile = dlgCommonDialog.FileName;
strDataFileTitle = dlgCommonDialog.Title;
if
(strDataFile.Length == 0)
return;
strDataPath =
Path.GetDirectoryName(strDataFile);
object argumentHolder = 1;
messageCallback("Extracting data from
" + strDataFile +
"!!! Please Wait");
strBin2TextPath = strStartDirectory +
"\\" +
"Bin2Txt.exe";
strDestinationDirectory = strDataPath +
"\\" +
"Bin2Txt.exe";
System.IO.File.Copy(strBin2TextPath,
strDestinationDirectory);
strNowRunThis = strDestinationDirectory;
ProcessStartInfo startBin2TextApp =
new
ProcessStartInfo(strNowRunThis, strDataFile +
" a");
startBin2TextApp.CreateNoWindow =
true;
startBin2TextApp.UseShellExecute =
false;
startBin2TextApp.WindowStyle =
ProcessWindowStyle.Hidden;
Process
exeProcess = null;
exeProcess =
Process.Start(startBin2TextApp);
messageCallback("Finished Extracting
data from " + strDataFile);
return;
catch (InvalidOperationException
inEx)
Console.WriteLine(inEx.Message); -
Workflow step (Approve Action) calling custom Java Service and "passing params"
Good Afternoon, Fellow Coders!
Normally I research and do proof of concepts until I find a solution but given super tight deadlines, I just don't have time - so I need your help.
I am trying to have an Workflow Approve Action (Workflow Exit Event idocScript call) call a Custom Component (Java Service) AND "pass" some kind of parameters (bare minimum dDocName)
In a perfect world it would be as simple as: processContentInfo(String dDocName, String xMyCode1, String xMyCode2);
But since I am calling the Java Service from idocScript (via executeService) I cannot directly pass params via the API.
Is there a simple way to do this??
It seems like if you can't directly pass params you could at least set them in the managed container (m_binder) and just know to pick them up on the Java side via some DataBinder like m_binder.getLocal(
Am I missing a simple idocScript function that will let you do this?
Note: I am NOT executing the Service from a URL so the normal ?param1¶m2 -> m_binder.getLocal solution is no good.
Also, Bex's book warns about Service Classes "not easily being able to call other UCM Services".... My Custom Service needs to do exactly that (as well as JDBC and other stuff). Is this really an issue??
Seems like as long as I have dDocName I could use RIDC to hit whatever I want as long as I know how to use a binder, etc - is there some mystic nuance that prevents this? Or was he just saying it's hard UNLESS you know RIDC well??
Any and all quality advice is appreciated! And please, try to give me a detailed answer as opposed to something vague like "try a Service Handler", I need something I can quickly digest.
Thanks in advance!You can set parameters for the service call by setting Idoc Script variables before you call executeService.
<$dDocName="TEST12345"$>
<$param1="09876"$>
<$param2="ABCDEFG"$>
These variables are then available via the service DataBinder.
Here is information about how to execute a service from a custom component. There should not be any issues doing this.
http://www.redstonecontentsolutions.com/5/post/2012/05/executing-a-service-from-aservicehandler.html
http://jonathanhult.com/blog/2012/06/execute-a-service-from-a-java-filter/
Jonathan
http://jonathanhult.com -
Calling one java program (with main method) from another
Hello,
How can I start another java program from one? Lets
say I want Second.java to start by calling it from
First.java. How do I do it? The two programs are given
below. Any help is appreciated.
Thanks,
Amanda
First.java
import java.io.*;
import java.lang.reflect.*;
public class First
public static void main(String[] args)
Process theProcess=null;
System.out.println("Hello World from First.java!");
String second=new String("Second.java");
//System.load(second);
//Runtime.getRuntime().load(second);
try
theProcess=Runtime.getRuntime().exec( "Second.java"
System.out.println("after exec");
catch (IOException ioe)
System.out.println(">>IOException thrown in
First.java while calling
Second.java."+ioe.getMessage());
Second.java
public class Second
public static void main(String[] args)
System.out.println("Hello World from Second.java!");
}Stop posting here. The crosspost remark was to alert others that there is a duplicate topic - all answers should be centralized in one so as to not waste people's time duplicating answers when they don't see both topics and the answers therein.
-
Shell script calling SQL Program and passing parameters
Hi guys,
Greetings from Toronto. Is it possible to pass a string or strings as parameters to a sql program from a shell script ?
Shell Script
# Accept system input parameters
p_user_id=$1
p_job_id=$2
sqlplus.exe -s $p_user_id @$RD_PATH/rd_test.sql $p_user_id $p_job_id
SQL Program (rd_test.sql)
-- Accept system input parameters
define p_user_id = &1
define p_job_id = &2
-- Wondering if its possible to pass these 3 parameters from a shell script program.
-- (1) rd_test-$p_job_id-3-1.lis
-- (2) RD_PRINTER(rd_test,3)
-- (3) t_data
select
t_data=''rd_test-'||'''$p_job_id'''||'-1-1.txt''
t_data_dir=''.''
ksh $RD_PATH/another_shell_prog.sh $p_user_id $p_job_id '||a.rd_value||' '
||b.rd_value||' rd_test-$p_job_id-3-1.lis $RD_PRINTER(rd_test,3) '||
'$t_data $t_data_dir'||'
exit_status=$?
check_command'
from rd_job_parameter b, rd_job_parameter a
where a.job_id = &2
and a.jp_module_id = 'RDTEST'
and b.job_id = a.job_id
and b.module_id = a.module_id
/As always, its not something I have to solve this minute. Any help would be appreciated
and I will be thinking of the problem.
Thanks
Raj
Edited by: Raj404261 on Jun 25, 2009 11:40 AM
Edited by: Raj404261 on Jun 25, 2009 5:29 PMHi Sean,
Thanks for the reply. I am not at work yet. I already do have the if condition to call 2 separate sql scripts. I was hoping them to be reduced to one sql script. That's why I was hoping to pass some of those values to the select statement as parameters.
Here is what I was hoping to pass from the shell script based on an IF condition. The good thing about it is that I can hard code these 3 parameters in the shell script in the IF and ELSE conditions. Is it possible to tag these 3 hard coded values in the command line after $p_job_id and then capture these 3 parameters in the SQL program ?
1. rd_test-$p_job_id-3-1.lis or rd_test-$p_job_id-3-1.lis
2. RD_PRINTER(rd_test,3) or RD_PRINTER(rd_test,4)
3. t_data=''rd_test-'||'''$p_job_id'''||'-1-1.txt''
Shell script :
# Accept system input parameters
p_user_id=$1
p_job_id=$2
if [condition]
sqlplus.exe -s $p_user_id @$RD_PATH/rd_test.sql $p_user_id $p_job_id
else
sqlplus.exe -s $p_user_id @$RD_PATH/rd_test.sql $p_user_id $p_job_id
fi
ksh $RD_PATH/another_shell_prog.sh $p_user_id $p_job_id '||a.rd_value||' '
||b.rd_value||' rd_test-$p_job_id-3-1.lis $RD_PRINTER(rd_test,3) '||
'$t_data $t_data_dir'||' -
Calling a JAVA program from an RFC in SAP ABAP
Hi All,
I have an RFC for a specific purpose in which I need to call a JAVA program whose path is given to me. Please suggest a possible process to do the same .
Your's <removed by moderator> responce is highly appreciated.
Thank you.
Edited by: Thomas Zloch on Nov 26, 2010 1:33 PM - priority normalisedHi Priyanth,
I am not sure but check this out
If you are using any commands , check if that command is configured in SM69 -
File to File and then Call ABAP Program and pass file name and location
Hi
I am new to PI and am working on the following requirement and some guidance would help:
A file is picked up from a third party server using FTP and is put in an SAP server in a specific location. After I have put in the file successfully, I need to call an ABAP program and provide the name and location of the file for further processing by the ABAP program.
Although I am familiar with File to File, how can I add in the ABAP call with the filename and location? I do not want to pass any other information to the ABAP program.
Thanks for your help.
ManojI think I get what you're saying. This additional file would have the file and the path in it's content. I would then use this as a source (FCC?) for Mapping with the RFC. Right?
Exactly and yes, FCC would be helpful
Would you have a sample OS script to do the above?
Actually it depends on the operating system on which your PI system is standing. For instance for Windows, you might try with the following as a start point (but I was not able to test it, so I can't guarantee it will do the job):
cmd.exe /C "%f %F > C:\target_directory\%DATE%_%TIME%.txt"
In case you needed more, try googling on "windows batch script" or similar.
Hope this helps,
Greg -
How to call a java program in javafx class(Urgent) and even vice versa
Hi all,
Here I have two questions:
1)
Please let me know how to call a javafx in java program...
I tried with the following code but it is not working..
The below is the java program in which I made a call to the Fx program.
FxMainLauncher.java
import net.java.javafx.FXShell;
public class FxMainLauncher {
public static void main(String[] args) throws Exception {
FXShell.main(new String[] {"HelloWorld.fx"});
2) How to call a java program in javafx class
Here is my javafx program
import check.*;
import javafx.ui.*
var instance = new MyJava();
//visible:true
System.out.println("Number is: {instance}");
Here is my java program
public class MyJava {
public static void main(String args[])
System.out.println("JAVAFX TO JAVA");
Even this is not working please let me know ASAP
Thanks in advance,
V.SrilakshmiGOT IT !!!
I had to change the name of the method in .h file generated by javah command. On doing
javac -d ../../classes HelloWorld.java
go to the ../../classes directory (where you have the class file) and do
javah HelloWorld
I got a HelloWorld.h file in which I had
JNIEXPORT void JNICALL Java_HelloWorld_display(JNIEnv *, jobject);
I added the package name too:
JNIEXPORT void JNICALL Java_GUI_HelloWorld_display(JNIEnv *, jobject);
The HelloWorldImp.c file should have the same name (ie with package) and be in the same directory(ie ../../classes)
compile and build the shared library to get "libhello.so" file
gcc -c -fPIC -I/usr/lib/j2sdk1.3/include -I/usr/lib/j2sdk1.3/include/linux HelloWorldImp.c
gives .o file
gcc -shared -o libhello.so HelloWorldImp.o
gives .so file
then run java with the command in my first message. It works.
Thanks for the reply "thedracle". -
CALL A JAVA PROGRAM FROM ABAP -- NEED HELP
Hi all,
Can somebody tell me how to call a java xml code from an ABAP program? First let me know if at all, is it possible to call a java program from SAP that is from an ABAP executable progam?
Please suggest me in this. All your inputs in this is valuable to me and highly appreciated.
Thanks in advance,
Vaishnavi VaradarajanHi,
Previous explanation i gave is not correct.
ABAP web services expose the function modules outside R/3, so that other technologies like Java can consume that webservice and read the data in R/3 using the function module.
For your requirement, create a Java web service to read the XML. Consume this webservice in ABAP. This way you can read the XML from ABAP.
Regards
Srikanth KV. -
Calling a Java Program from another
Hi,
I am putting together a Java program which will launch other Java programs.
I was thinking of doing this by calling unix scripts from my java program by getting an instance of the Runtime object and then calling the exec method with the script name.
I am just wondering what is the best practice when doing this? i.e., dealing with timeout issues, and errors in the scripts etc.
I have read this article, which is quite good: http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=1
Is there any code available on the web that deals with all of the basic error scenarios?
Is it good practice to use a java program to call another java program? Or is there a better way of doing this?
The main reason I am using java is because I am most familiar with it and I need to connect to a database as well and do some manipulation of results returned.
Any thoughts or suggestions would be much appreciated.
Message was edited by:
LondonJavaDevThanks Prometheuzz
Is the main difference between your suggestion and
using the Runtime.getRuntime().exec(cmd) way of doing
things is that in the former both eill run as the
same process (Thread) but in the second scenario the
.getRuntime().exec(cmd) will start a separate new
thread?
Many ThanksCorrect. But you can create a sort of wrapper class for A which implements Runnable and stuff it in it's own thread. If you're dealing with Java code only, I advise you to create threads yourself instead of letting your OS handle them.
Here's a demo:
class Foo {
public static void main(String[] args) {
(new Thread(new ARunner())).start();
B.main(null);
class ARunner implements Runnable {
public void run() {
A.main(null);
class A {
public static void main(String[] args) {
try {
Thread.sleep(3000);
} catch (InterruptedException e) { /* ... */ }
System.out.println("A");
class B {
public static void main(String[] args) {
System.out.println("B");
}Of course, you can create a wrapper for B as well. -
Requesting an overview of how to call a Java program from EBS.
Hi,
I am an experienced Java developer in the middle of an implementation of EBS 12g. I am very new to EBS and I'm not sure where to start on this. I need to provide users the ability to call a Java program that prints a report from EBS. I would be grateful if somebody would outline the general approach that should be used. Links to documentation/tutorials are appreciated also.
Thanks,
MikeHi,
I need to provide users the ability to call a Java program that prints a report from EBS. Are you referring to Java concurrent programs? If yes, please see the documents referenced in this thread.
Java Concurrent Programs
Java Concurrent Programs
Regards,
Hussein -
Type conversion when calling a java program in form 6i
Hi,
I would like to call a java program in form 6i. The java program takes a date parameter in. When I call the java program in form, how can I pass a date parameter to it?
-- Method: isSystemDate (Ljava/util/Date;)Ljava/lang/String;
FUNCTION isSystemDate(
obj ORA_JAVA.JOBJECT,
a0 ORA_JAVA.JOBJECT) RETURN VARCHAR2;
Thanks.hi Tony,
Perhaps you could notice that i myself commented in the beginning itself that I know that XE does not support JAVA. I wanted to know if there is any other way of calling java program from apex, perhaps from javascript,etc.
if you RE READ the comment from Munky , he says that I could use PL/SQL for my objective and I have answered WHY it does not satisfy my problem
thanks
Edited by: eric clapton on Nov 14, 2010 9:11 AM -
Calling a java program from a perl CGI
The perl program takes form data, does stuff with it, writes it to a file, and then calls a java program to encrypt it, and email it.
When I telnet to the server, I can run the java program using:
java CryptoMail.class [email protected] data.txt
The java program uses jar files which are defined in the Classpath in an .sh script in the etc/profile.d/ directory.
When I run the perl cgi from the web, it doesn't work. I figured that it wasn't getting the classpath defined because the user wasn't actually logging in so I tried it with java -classpath etc...
Any ideas???
I tried the following:
==================
$cmdtorun='/usr/j2sdk1.4.0_02/bin/java CryptoMail $email $file';
system($cmdtorun);
==================
and also tried variations of the following:
==================
/usr/j2sdk1.4.0_02/bin/java -classpath .:/home/sites/site1/web/cgi-bin/activation.jar:/home/sites/site1/web/cgi-bin/mail.jar /home/sites/site1/web/cgi-bin/CryptoMail [email protected] /home/sites/site1/web/cgi-bin/wellsfargo.txt
==================>
Any ideas???Write a script file that explicitly paths everything.
Test it by setting the class path and path to nothing in the environment and seeing if it works.
Redirect errors from everything to a log file.
Then run the script from your perl program. Verify that it did not return any errors. Verify there are no errors in the log file. -
How can I call a java-program as receiver
Hi Folks,
I have to call a java program, based on the XI-Server as receiver. My qustions are:
What is the right adapter type
What are the parameters to give the xml to the program
Thanks a lot
matthiasHi Mathias,
I would suggest, generate a java proxy of ur inbound interface (reciever).
1. In the java proxy implementation method you will
have access to the message sent to the interface,
2. You could then use this message(XML) and Call ur
custom java program from the java proxy.
here is a link on how to implement java proxies
http://help.sap.com/saphelp_nw04/helpdata/en/14/80243b4a66ae0ce10000000a11402f/frameset.htm
Naveen -
Difference between a java program and a java class
Hi there,
What is the difference between a java program and a java class?HI,
A java class is an object - described in a .class file - which has been given properties and behaviours and which can be instantiated in a program.
A java program( application ) consists of at least one class (one of which must be declared public) and which executes its main() method ( of the public class ) when it is started.
Every program is a class but not every class is a program.
Examples:
A java program
// this simple program will print out the first command line argument you put
// in after calling : java ScreenWriter "arguments"
class ScreenWriter
public static void main( String [] args )
if( args.length > 0 )
System.out.println( args[0] );
A java class
//the Math class is already defined in the java.lang package
//and contains a constant for PI
//So I can include the Math class with the PI constant in my simple program
//and now I have a program that involves my ScreenWriter class and the Math class too.
class ScreenWriter
public static void main( String [] args )
if( args.length > 0 )
System.out.println( args[0] );
System.out.println( "The value of Pi is: " + Math.PI );
When you see package and import declarations at the start of a program they are there to ensure the compiler knows which classes are used in the program.
Hope that helps,
Terry
Maybe you are looking for
-
I recently updated my iTunes to the latest version; however, when I go to purchase songs now, it says I need to verify my apple ID. It tells me to click OK to follow the instructions on how to do so. When I click OK, it says an email has been sent
-
Can't see previous purchases menu anymore. Can no longer download previous purchases.
-
Non-admin user can not logon to web pages
I setup an iMac, I am the administrator and I set up a non-admin user. I also setup parental controls to their default settings. The user can log on to their account but when they go to a web page, any web page, that requires a logon, the authenticat
-
After firmware update ipod touch not working with my Sony Home Theater DAV HDX287WC any suggestions
Is there a solution to play music from my iPod touch on my Sony Home Theater System DAV HDX 287WC after recent firmware/software upgrade? However, I am still able to play music through my ipod classic, but I am really missing the the functionality of
-
Function Module required for IBASE component
Hi Experts, Is there any FM which can get the warranty start date with IBASE component?? Warranty is assigned to IBASE component under relationship tab. Points shall be rewarded for sure Regards, Madhu