Passing parameter to VB Script from Java file

I have a jhtml(read java) page which is trying to create a virtual directory in IIS. The servlet container run on IIS. I have a VB Script file (.vbs) which creates the virtual directory. Now the vbs file needs a parameter to create a new directory every time and the directory name should be the parameter name. I am able to run the vbs from java but the parameter passing doesn't work.
String acctname = "test";
String path = "d:/ScriptTool/CreateAccountWebIIS.vbs";
String fullpath = path+" "+ "/c:"+acctname;
System.out.println("path = "+fullpath);
Process process1;
Runtime userRuntime = Runtime.getRuntime();
try
process1 = userRuntime.exec("wscript.exe " + fullpath);
discussed options
1) convert vbs to exe
2) use batch file

If you're creating a string that is going to be used as a file name by a Windows program on a Windows command line, then you have to use the backslash to separate directories in the path.String path = "d:\\ScriptTool\\CreateAccountWebIIS.vbs";Forward slashes are okay (actually, preferred) in Java code for use by Java classes but once you hand it over to Windows you do need to follow the Windows rules.

Similar Messages

  • Passing argument to shell script from java program

    str="/bin/sh -c /root/PWAppSh/StartSH.sh";
    p = rt.getRuntime().exec(str);
    above is the code snippet of java program for calling the shellscript
    when i pass a argument to the shell script from my java program it wont get accepted in shell script as an input
    when i do following changes in above code it wont work :---
    str="/bin/sh -c /root/PWAppSh/StartSH.sh para1 para2 para3 ";
    p = rt.getRuntime().exec(str);
    para1,para2 and para3 wont get as argument for the shell script
    how this can be done
    thanks
    reply "ARGENT"

    Argent.
    Read this:
    Navigate yourself around pitfalls related to the Runtime.exec() method

  • How can i pass the  parameter for strored procedure from java

    dear all,
    I am very new for stored procedure
    1. I want to write the strored procedure for insert.
    2. How can i pass the parameter for that procedure from java.
    if any material available in internet create procedure and call procedure from java , and passing parameter to procedure from java

    Hi Ram,
    To call the callable statement use the below sample.
    stmt = conn.prepareCall("{call <procedure name>(?,?)}");
    stmt.setString(1,value);//Input parameter
    stmt.registerOutParameter(2,Types.BIGINT);//Output parameter
    stmt.execute();
    seq = (int)stmt.getLong(2);//Getting the result from the procedure.

  • Example: Executing a shell script from java

    Hi. There are many other posts in the forums related to executing a unix script from java, but I wanted to post another example that I thought might be helpful...
    The key thing to executing the script is to include the -c switch for the sh command. This tells the sh command that you are passing a string to be interpreted as input. Without this switch, the script does not execute as you'd expect it to. Also, use a string array to pass each part of the sh command.
    Here is a working sample class, along with a test script to execute it:
    public class TestShellScript {
    public static void main(String[] args)
    String[] chmod = {"chmod","777","testscript1"};
    String[] runscript = {"sh","-c","./testscript1 > jdata.out"};
    Runtime rtime = Runtime.getRuntime();
    try
    rtime.exec(chmod); // Set the authorities for testing
    rtime.exec(runscript); // Run the script with redirection
    catch (IOException e)
    e.printStackTrace();
    rtime = null;
    Here is a test script to wrap the java call:
    #!/bin/sh
    cd /<your script dir>
    export -s CLASSPATH=/<your jar dir>/TestShellScript.jar
    export -s PATH=/<your script dir>:/usr/bin
    java TestShellScript
    - Hope this helps.

    I don't know exactly but the code written below is working fine try the same with your code .Even with your code instead running the code with
    " ./<filename> ",if you execute it with "sh <filename>" command without changing the mode of the file it is executing properly.
    import java.io.*;
    import java.util.*;
    public class ScriptBuilder
    public ScriptBuilder()
    public void writeScript() throws java.io.IOException
    FileWriter writer = new FileWriter(new File("test_script"));
    writer.write("#! /bin/sh\n");
    writer.write("ll>/home/faiyaz/javaprac/checkll");
    writer.flush();
    writer.close();
    Runtime rt= Runtime.getRuntime();
    rt.exec("chmod 777 test_script");
    rt.exec("./test_script");
    } public static void main (String[] args)throws java.io.IOException
    ScriptBuilder sb = new ScriptBuilder();
    sb.writeScript();
    }

  • Invoking a bash shell script from Java code

    Hi All
    I am trying to invoke a Bash shell script using java code. The arguments required are "source wmGenPatch <source dir> <destination dir> no_reverse.
    in the code I have specified the arguments considering the cannonical paths of the files as the code may run on Unix or windows platform.
    I am getting a error while invoking Runtime.getRuntime().exec(args). The error is as follows :
    "The Error Occurred is: CreateProcess: source D:\Package4.0\workspace\DiffEngineScripts\v4a02\wmGenPatch D:\Package4.0\workspace\fromImageFilesDir\ D:\Package4.0\workspace\toImageFilesDir\ no_reverse error=2"
    It seems that error=2 indicates that the 'file not found' exception. But i can see the directories referred to in the error at place in the workspace.
    Kindly advice.
    Thanks in advance.

    Hi All
    I am pretty new to invoking bash shell scripts from java and not sure if i am progressing in right direction.
    The piece of code tried by me is as follows
    try {
                   currentDir = f.getCanonicalPath();
              } catch (IOException e) {
              if (currentDir.contains("/")) {
                   separator = "/";
              } else {
                   separator = "\\";
              String args[] = new String[7];
              args[0] = "/bin/sh";
              args[1] = "-c";
              args[2] = "source";
              args[3] = currentDir + separator + "DiffEngineScripts" + separator
                        + "v4a02" + separator + "wmGenPatch";
              args[4] = sourceFileAdd;
              args[5] = destFileAdd;
              if (isReverseDeltaRequired) {
                   args[6] = "reverse";
              } else {
                   args[6] = "no_reverse";
              try {
                   Process xyz = Runtime.getRuntime().exec(args);                              
                   InputStream result = xyz.getInputStream();
                   InputStreamReader isr = new InputStreamReader(result);
                   BufferedReader br = new BufferedReader(isr);
                   String line = null;
                   while ( (line = br.readLine()) != null)
                        System.out.println(line);
                   int exitVal = xyz.waitFor();
                   System.out.println("Leaving Testrun.java");
              } catch (Throwable t) {
                   t.printStackTrace();               
    and on running the same i am getting Java.io.IOException with the stack trace
    java.io.IOException: CreateProcess: \bin\sh -c source D:\Package4.0\workspace\DiffEngineScripts\v4a02\wmGenPatch D:\Package4.0\workspace\fromImageFilesDir\ D:\Package4.0\workspace\toImageFilesDir\ no_reverse error=3
    kindly advice
    Thanks in advance

  • Call PERL script from JAVA

    I am facing a problem in running a PERL script in JAVA in UNIX box..
    I am able to call ther perlscript.
    Perl script has
    #! /usr/local/bin/perl
    print "\nEnter Your Name :";
    $name = <>;
    print "\nYour Name is : $name\n";
    exit 0;
    Perl script request for the INPUT(name) .
    My Java program is
    File perlfile = new File("test.pl");
    Runtime runtime = Runtime.getRuntime();
    Process process = runtime.exec("perl "+perlfile);
    Here is the problem tat IT IS says error =2 ..What has to be the solution so tat i can CALL PERL SCRIPT as similiar to running it separatly in prompt { >perl test.pl }
    PLEASE help me on this....

    In the PERL SCRIPT (test.pl)
    LINE 1 : #! /usr/local/bin/perl
    LINE 2 : print "\nEnter Your Name :"; .
    LINE 3 : $name = <>;
    LINE 4 : print "\nYour Name is : $name\n";
    LINE 5 : exit 0;
    When i run this script in perl test.pl in prompt (UNIX BOX), i am gettin the request for name "Enter Your Name:____ " but when i call this script from Java it doesn't request for name and moreover the process doesnt ends (use ctrl+c to come out of the process).When i come out forcefully it shows the ERROR=2.
    My requirement is such tat need to call a PERL SCRIPT from java so tat java process give the control to PERL script and it will continue the process..
    Sample scenario:
    Java move a file and store it in a new FOLDER
    MY perl script will read the file in new FOLDER.
    here the perl script will get the file name for processing... My issue comes here .$name is not be prompted while calling thro java..

  • An error The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered after launching a ps1 script from cmd file.

    I'm trying to load sharepoint script from *.cmd file. 
    I have Sharepoint 2010 installed on Windows 7 x64 and SQL server 2008r2.
    My cmd file is: 
    Powershell -v 2 -NonInteractive -NoLogo -File 1.ps1
    My sharepoint file 1.ps1 is:
    $snapin="Microsoft.SharePoint.PowerShell"
    if ($action -eq $null -or $action -eq '')
    {<br />
    # Action by default is complete uninstallation.
    $action='uninstall'
    $uninstall = $true
    else
    $action = $action.ToLower()
    switch($action)
    { $_ -eq "uninstall" } { $uninstall = $true; break }
    { $_ -eq "removesolution" } { $removeSolution = $true; break }
    { $_ -eq "deactivatecorpus" } { $deactivateCorpus = $true; break }
    { $_ -eq "deactivatesupport" } { $deactivateSupport = $true; break }
    default { Write-Host -f Red "Error: Invalid action: $action "; Exit -1 }
    Check the Sharepoint snapin availability.
    if (Get-PSSnapin $snapin -ea "silentlycontinue")
    Write-Host "PS snapin $snapin is loaded."
    elseif (Get-PSSnapin $snapin -registered -ea "silentlycontinue")
    Write-Host "PS snapin $snapin is registered."
    Add-PSSnapin $snapin
    Write-Host "PS snapin $snapin is loaded."
    else
    Write-Host -f Red "Error: PS snapin $snapin is not found."
    Exit -1
    $url = "http://pc1/sites/GroupWork/"
    $site= new-Object Microsoft.SharePoint.SPSite($url )
    $loc= [System.Int32]::Parse(1033)
    $templates= $site.GetWebTemplates($loc)
    foreach ($child in $templates){ write-host $child.Name " " $child.Title}<br />
    $site.Dispose()
    The script works fine from the Sharepoint 2010 management shell after launching the shell from the start menu (or from windows cmd by entering powershell -v 2):
    PS C:\2> .\1.ps1 
    PS snapin Microsoft.SharePoint.PowerShell is loaded.
    GLOBAL#0 Global template
    STS#0 Team Site
    STS#1 Blank Site
    STS#2 Document Workspace
    MPS#0 Basic Meeting Workspace
    MPS#1 Blank Meeting Workspace
    MPS#2 Decision Meeting Workspace
    MPS#3 Social Meeting Workspace
    MPS#4 Multipage Meeting Workspace
    CENTRALADMIN#0 Central Admin Site
    WIKI#0 Wiki Site
    BLOG#0 Blog
    SGS#0 Group Work Site
    TENANTADMIN#0 Tenant Admin Site
    {248A640A-AE86-42B7-90EC-45EC8618D6B4}#MySite2 MySite2
    {95629DC2-03B1-4C92-AD70-BC1FEAA49E7D}#MySite1 MySite1
    {7F01CFE4-F5E2-408B-AC87-E186D21F624C}#NewSiteTemplate NewSiteTemplate
    PS C:\2>
    I have an access to the database Sharepoint_Config from current domain user and from other 2 users. All users have db_owner rights to the Sharepoint_Config database. But
    i've loaded in windows from the user which is dbo in the database (dbo with windows authentication with domain\username for the current user). The dbo user has do_owner rights in the Sharepoint_Config database. I've tried to login under other users and launch
    the cmd file but without success.
    My PowerShell has version 2.0: 
    PS C:\2> $psversiontable
    Name Value
    CLRVersion 2.0.50727.5477
    BuildVersion 6.1.7601.17514
    PSVersion 2.0
    WSManStackVersion 2.0
    PSCompatibleVersions {1.0, 2.0}
    SerializationVersion 1.1.0.1
    PSRemotingProtocolVersion 2.1
    After launching the script from 1.cmd file i get an errors:
    C:\2>Powershell -v 2 -NonInteractive -NoLogo -File 1.ps1
    PS snapin Microsoft.SharePoint.PowerShell is registered.
    The local farm is not accessible. Cmdlets with FeatureDependencyId are not regis
    tered.
    Could not read the XML Configuration file in the folder CONFIG\PowerShell\Regist
    ration.
    Could not find a part of the path 'C:\2\CONFIG\PowerShell\Registration'.
    No xml configuration files loaded.
    Unable to register core product cmdlets.
    Could not read the Types files in the folder CONFIG\PowerShell\types.
    Could not find a part of the path 'C:\2\CONFIG\PowerShell\types'.
    "No Types files Found."
    Could not read the Format file in the folder CONFIG\PowerShell\format.
    Could not find a part of the path 'C:\2\CONFIG\PowerShell\format'.
    No Format files Found.
    PS snapin Microsoft.SharePoint.PowerShell is loaded.
    New-Object : Exception calling ".ctor" with "1" argument(s): "The Web applicati
    on at http://Pc1/sites/GroupWork/ could not be found. Verify t
    hat you have typed the URL correctly. If the URL should be serving existing con
    tent, the system administrator may need to add a new request URL mapping to the
    intended application."
    At C:\2\1.ps1:48 char:18
    + $site= new-Object <<<< Microsoft.SharePoint.SPSite($url )
    + CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvoca
    tionException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.Power
    Shell.Commands.NewObjectCommand
    Please help me. I don't understand why the script is launched from the sharepoint management shell but doesn't work from the cmd file.

    I have an answer for my problem:  for solving a problem I've made several steps:
    1. Run farm installation under AD admin credentials - runas /user:Domain1\DomainAdmin1 "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN\psconfigui.exe".
    This user has been added as farm administrator in the wizard.
    This user has been added as DBO in the SQL Server. (This is the main difference with my previous attempts)
    2. Execute a command Add-SPShellAdmin Domain1\UserAccount1 in
    the Management Shell of Sharepoint.
    3. Run SQL server and add Sharepoint_Shell_Access to the Domain1\UserAccount1
    (my main account) in the Config database
    4. Run CMD file only from Start->Run menu. 
    runas /user:Domain1\UserAccount1 "C:\1.cmd".
    Do not use Total Commander command prompt or file list for executing *.cmd of *.bat files without root administrator account.
    Thanks all for help.

  • Looking for a way to pass parameter to external list from infopath

    Hey, i have a Sharepoint 2010 list for which I want to create Infopath form. I have an external content type and external list based on it.
    I want to prepopulate some fields in my Sharepoint list with data from external list. I tried to use external list as a secondary data source and query it for needed values. The issue I encounter is that my ECT has a finder with filter and I can't figure
    out how to pass a value to this filter within infopath.
    How can it be done with infopath? How can I pass the filter value to the external list using Infopath?

    Hi,
    According to your post, my understanding is that you wanted to pass parameter to external list from infopath.
    You need to query the external list from InfoPath using coding and CAML Query.
    Here is a similar thread for your reference:
    http://sharepoint.stackexchange.com/questions/33575/filtering-sharepoint-external-list-bcs-from-infopath
    Thanks,
    Linda Li
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Linda Li
    TechNet Community Support

  • Convert from java file to cap file

    Dear Pro,
    Please help me this problem,
    I'm building a applet in eclipse. Now, I want to convert from java file to cap file to load it into javacard.
    I need repair what tools and do what, please help me!
    Thanks & Best Regards,
    KeillyNguyen

    Run -> Run Configuration -> Double click Java Card Application -> Click Run
    After that, the CAP file will be generated in the bin directory.
    Are you come from VN? Im Vietnamese :) Nice to meet you

  • How to execute unix shell script from Java ...

    Hi,
    Anyone know how to execute unix shell script from Java?
    Suppose I have several shell scripts written in perl or tcl or bash.
    I just want to catch the output of that script.
    Is there any ready to use module/object for this?
    Please let me know, this is quite urgent for my study assigment.
    Thanks in advance,
    Regards,
    me

    Look up Runtime.exec()

  • Run a UNIX Script from java

    Hi,
    how can i run a unix script from java application. This java application is on windows.
    How can i do this.
    thanks,

    Hi,
    how can i run a unix script from java application.
    This java application is on windows.
    So I think it's safe to assume that the target script is on a remote unix server.
    Take a look at http://sourceforge.net/projects/sshtools/

  • Excute unix script from java.

    Hi need to excute unix script from java application.
    My code is:
    public class Test
    public static void main(String args[])
         try{
         p = Runtime.getRuntime().exec("./qfe0"); //qfe0 is the name of the script.
    p.waitFor();
    catch(Exception e)
    e.printStackTrace();
    My problem is that using the waitFor() statement stuck the the script. if i don't use the waitFor() it works good but then i don't know when the script is finished.
    Any idea?

    The problem is likely to be that you script is either waiting for input or has filled the stdout buffer and you are not emptying it. Search this forum for this as its been answered many times before.

  • How execute Unix script from java?

    Can I execute Unix script from java?

    Yes. Using ProcessBuilder. And read [When Runtime.exec() wont|http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html]. It's old, but pretty much all of it is still true.

  • Is it possible to execute SAPGUI scripts from java program?

    Hi everyone..
         I need to develop an java applications that executes the SAPGUI script or any technique that execute set of transaction as client.
         Is it possible to execute SAPGUI scripts from java program? if so, how it can be achieved? is there any other technique to achieve above mention scenario?.
         it will be more helpful, if docs related to that are shared..
         Thanks in advance

    Oh, bummer. Would be much more convenient if I could just use iTunes for everything. Can't stand WMP. I wonder if WinAmp might be a good compromise?
    Thanks for this answer . . .
    Sharon

  • Invoking unix shell scripts from java?

    Hi,
    could someone explain to me how one wuld invoke unix shell scripts from java.
    Also, could you invoke Visual Basic scripts from java.
    Finally, could you do this from an EJB?
    thanks for any help....
    sudu

    I just posted a snippet of this solution in the topic about widows commands chech it out it works just fine for unix shell scripts.
    --Ian                                                                                                                                                                                                                                                                                       

Maybe you are looking for