Running 5 commands using array elements and waiting between?

Hi All,
Trying to learn PS so please be patient with me ;)
System: PSv3 on Win2012 server running WSUS role
I am wanting to execute 5 commands using a 'foreach' loop but wait until one finishes before moving onto the next. Can you please check out what I have and provide some suggestions of improvement? or scrap it completely if it's rubbish :(
Current code:
#### SCRIPT START ####
#Create and define array and elements
$Array1 = @(" -CleanupObsoleteComputers"," -DeclineSupersededUpdates -DeclineExpiredUpdates"," -CleanupObsoleteUpdates"," -CleanupUnneededContentFiles"," -CompressUpdates")
#Run the cleanup command against each element
foreach ($element in $Array1) {
Get-WsusServer | Invoke-WsusServerCleanup $element -Whatif
#### SCRIPT END ####
I am assuming that I need to use @ to explicitly define elements since my second element contains two commands with a space between?
The cleanup command doesn't accept '-Wait' so I'm not sure how to implement a pause without just telling it to pause for x time; not really a viable solution for this as the command can sometime take quite a while. They are pretty quick now that I do
this all the time but just want it to be future proof and fool proof so it doesn't get timeouts as reported by others.
I have found lots of code on the net for doing this remotely and calling the .NET assemblies which is much more convoluted. I however want to run this on the server directly as a scheduled task and I want each statement to run successively so it
doesn't max out CPU and memory, as can be the case when a single string running all of the cleanup options is passed.
Cheers.

Thank you all for your very helpful suggestions, I have now developed two ways of doing this. My original updated (thanks for pointing me in the right direction Fred) and Boe's tweaked for my application (blew my mind when I first read that API code
Boe). I like the smaller log file mine creates which doesn't really matter because I am only keeping the last run data before trashing it anyway. I have also removed the verbose as I will be running it on a schedule when nobody will be accessing it anyway,
but handy to know the verbose commands ;)
Next question: How do I time these to see which way is more efficient?
My Code:
$Array1 = @("-CleanupObsoleteComputers","-DeclineSupersededUpdates","-DeclineExpiredUpdates","-CleanupObsoleteUpdates","-CleanupUnneededContentFiles","-CompressUpdates")
$Wsus = Get-WsusServer
[String]$Logfile = 'C:\Program Files\Update Services\LogFiles\ArrayWSUSCleanup.log'
[String]$Logfileold = 'C:\Program Files\Update Services\LogFiles\ArrayWSUSCleanup.old'
If (Test-Path $Logfileold){
Remove-Item $Logfileold
If (Test-Path $Logfile){
Rename-Item $Logfile $Logfileold
foreach ($Element in $Array1)
Get-Date | Out-File -FilePath $LogFile -Append -width 50
Write-Output "Performing: $($Element)" | Out-File -FilePath $LogFile -Append -width 100
. Invoke-Expression "`$Wsus | Invoke-WsusServerCleanup $element" | Out-File -FilePath $LogFile -Append -width 100
Logfile Output {added 1 to show what it looks like when items are actions}:
Wednesday, 27 August 2014 2:14:01 PM
Obsolete Computers Deleted:1
Wednesday, 27 August 2014 2:14:03 PM
Obsolete Updates Deleted:1
Wednesday, 27 August 2014 2:14:05 PM
Expired Updates Declined:1
Wednesday, 27 August 2014 2:14:07 PM
Obsolete Updates Deleted:1
Wednesday, 27 August 2014 2:14:09 PM
Diskspace Freed:1
Wednesday, 27 August 2014 2:14:13 PM
Updates Compressed:1
Boe's Updated Code:
[String]$WSUSServer = 'PutWSUSServerNameHere'
[Int32]$Port = 8530 #Modify to the port your WSUS connects on
[String]$Logfile = 'C:\Program Files\Update Services\LogFiles\APIWSUSCleanup.log'
[String]$Logfileold = 'C:\Program Files\Update Services\LogFiles\APIWSUSCleanup.old'
If (Test-Path $Logfileold){
Remove-Item $Logfileold
If (Test-Path $Logfile){
Rename-Item $Logfile $Logfileold
[Void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")
$Wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($WSUSServer,$False,$Port)
$CleanupMgr = $Wsus.GetCleanupManager()
$CleanupScope = New-Object Microsoft.UpdateServices.Administration.CleanupScope
$Properties = ("CleanupObsoleteComputers","DeclineSupersededUpdates","DeclineExpiredUpdates","CleanupObsoleteUpdates","CleanupUnneededContentFiles","CompressUpdates")
For ($i=0;$i -lt $Properties.Count;$i++) {
$CleanupScope.($Properties[$i])=$True
0..($Properties.Count-1) | Where {
$_ -ne $i
} | ForEach {
$CleanupScope.($Properties[$_]) = $False
Get-Date | Out-File -FilePath $LogFile -Append -width 50
Write-Output "Performing: $($Properties[$i])" | Out-File -FilePath $LogFile -Append -width 100
$CleanupMgr.PerformCleanup($CleanupScope) | Out-File -FilePath $LogFile -Append -width 200
Logfile Output {added 1 to show what it looks like when items are actions}:
Wednesday, 27 August 2014 2:32:30 PM
Performing: CleanupObsoleteComputers
SupersededUpdatesDeclined : 0
ExpiredUpdatesDeclined    : 0
ObsoleteUpdatesDeleted    : 0
UpdatesCompressed         : 0
ObsoleteComputersDeleted  : 1
DiskSpaceFreed            : 0
Wednesday, 27 August 2014 2:32:32 PM
Performing: DeclineSupersededUpdates
SupersededUpdatesDeclined : 1
ExpiredUpdatesDeclined    : 0
ObsoleteUpdatesDeleted    : 0
UpdatesCompressed         : 0
ObsoleteComputersDeleted  : 0
DiskSpaceFreed            : 0
Wednesday, 27 August 2014 2:32:34 PM
Performing: DeclineExpiredUpdates
SupersededUpdatesDeclined : 0
ExpiredUpdatesDeclined    : 1
ObsoleteUpdatesDeleted    : 0
UpdatesCompressed         : 0
ObsoleteComputersDeleted  : 0
DiskSpaceFreed            : 0
Wednesday, 27 August 2014 2:32:36 PM
Performing: CleanupObsoleteUpdates
SupersededUpdatesDeclined : 0
ExpiredUpdatesDeclined    : 0
ObsoleteUpdatesDeleted    : 1
UpdatesCompressed         : 0
ObsoleteComputersDeleted  : 0
DiskSpaceFreed            : 0
Wednesday, 27 August 2014 2:32:38 PM
Performing: CleanupUnneededContentFiles
SupersededUpdatesDeclined : 0
ExpiredUpdatesDeclined    : 0
ObsoleteUpdatesDeleted    : 0
UpdatesCompressed         : 0
ObsoleteComputersDeleted  : 0
DiskSpaceFreed            : 1
Wednesday, 27 August 2014 2:32:43 PM
Performing: CompressUpdates
SupersededUpdatesDeclined : 0
ExpiredUpdatesDeclined    : 0
ObsoleteUpdatesDeleted    : 0
UpdatesCompressed         : 1
ObsoleteComputersDeleted  : 0
DiskSpaceFreed            : 0

Similar Messages

  • Run shell commands using java program

    Hi guys,
    I am trying to run shell commands like cd /something and ./command with arguments as follows, but getting an exception that ./command not found.Instead of changing directory using "cd" command I am passing directory as an argument in rt,exec().
    String []cmd={"./command","arg1", "arg2", "arg3"};
    File file= new File("/path");
    try{
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec(cmd,null,file);
    proc.waitFor();
    System.out.println(proc.exitValue())
    BufferedReader buf = new BufferedReader(new InputStreamReader(proc.getInputStream()));
    catch(Exception e)
    {e.printStackTrace();
    So can anyone please tell me what is wrong with this approach? or is there any better way to do this?
    Thanks,
    Hardik

    warnerja wrote:
    What gives you the idea that the process to execute is called "./command"? If this is in Windows, it is "cmd.exe" for example.It does not have to be cmd.exe in Windows. Any executable or .bat file can be executed as long as one either specifies the full path or the executable is in a directory that is in the PATH.
    On *nix the file has to have the executable bit set and one either specifies the full path or the executable must be in a directory that is in the PATH . If the executable is a script then if there is a hash-bang (#!) at the start of the first line then the rest of the line is taken as the interpreter  to use. For example #!/bin/bash or #!/usr/bin/perl .
    One both window and *nix one can exec() an interpreter directly and then pass the commands into the process stdin. The advantage of doing this is that one can change the environment in one line and it  remains in effect for subsequent line. A simple example of this for bash on Linux is
    import java.io.OutputStreamWriter;
    import java.io.Writer;
    public class ExecInputThroughStdin
        public static void main(String args[]) throws Exception
            final Process process = Runtime.getRuntime().exec("bash");
            new Thread(new PipeInputStreamToOutputStreamRunnable(process.getErrorStream(), System.err)).start();
            new Thread(new PipeInputStreamToOutputStreamRunnable(process.getInputStream(), System.out)).start();
            final Writer stdin = new OutputStreamWriter(process.getOutputStream());
            stdin.write("xemacs&\n");
            stdin.write("cd ~/work\n");
            stdin.write("dir\n");
            stdin.write("ls\n");
            stdin.write("gobbldygook\n"); // Forces output to stderr
            stdin.write("echo $PATH\n");
            stdin.write("pwd\n");
            stdin.write("df -k\n");
            stdin.write("ifconfig\n");
            stdin.write("echo $CWD\n");
            stdin.write("dir\n");
            stdin.write("cd ~/work/jlib\n");
            stdin.write("dir\n");
            stdin.write("cat /etc/bash.bashrc\n");
            stdin.close();
            final int exitVal = process.waitFor();
            System.out.println("Exit value: " + exitVal);
    }One can use the same approach with Windows using cmd.exe but then one must be aware of the syntactic differences between commands running in .bat file and command run from the command line. Reading 'help cmd' s essential here.
    The class PipeInputStreamToOutputStreamRunnable in the above example just copies an InputStream to an OutputStream and I use
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    public class PipeInputStreamToOutputStreamRunnable implements Runnable
        public PipeInputStreamToOutputStreamRunnable(InputStream is, OutputStream os)
            is_ = is;
            os_ = os;
        public void run()
            try
                final byte[] buffer = new byte[1024];
                for (int count = 0; (count = is_.read(buffer)) >= 0;)
                    os_.write(buffer, 0, count);
            } catch (IOException e)
                e.printStackTrace();
        private final InputStream is_;
        private final OutputStream os_;
    }

  • First of all, I would have to say that getting in touch with you is a nightmare and I am not at all happy that I can't just email or live chat with someone who can help!  I am not a technical person, I just want to be able to use Photoshop Elements and ge

    First of all, I would have to say that getting in touch with you is a nightmare and I am not at all happy that I can't just email or live chat with someone who can help!  I am not a technical person, I just want to be able to use Photoshop Elements and get on with it. I bought Photoshop Elements via Amazon some months ago and it worked fine.  I then got a message that advised that the trial version would expire, which it subsequently has (I have been trawling your site for weeks and weeks trying to find an email or phone contact to get some assistance).  Relucltantly, I am now typing this - and I suspect it will not help in the slightest!  I bought the FULL not TRIAL edition of Photoshop Elements and I have contacted Amazon who confirmed this, but say I need to contact you.  Can you please let me know how I can resolve this?  Louise A Fraser

    Hi Louise, sorry to hear of your problems. This is not Adobe. We are mainly support volunteers, other users like you, trying to help one another.  You need to contact Adobe directly for activation and licencing issues. Click the link below. Use the dropdown menu for boxes (1) & (2) to scroll down the list and choose:
    1. Adobe Photoshop Elements
    2. Adobe ID, and signing-in
    3. Click on the blue button: Still need help? Contact us – then click the area marked chat 24/7, then click “start chat ”
    It’s usually possible to start a live chat, if an Adobe agent is free, and often to get the problem fixed right away. Have your serial number available. The agent can directly troubleshoot your system if you agree to activate the Adobe Connect add-on. Don’t let them pass the buck. Stay connected and ask to speak with a supervisor if necessary.
    Click here to get help now Contact Customer Care

  • I want run some command using java

    hi all,
    i want run command using java code.
    from cell prompt when i run this command 'mysqldump test > /home/DBNAME.sql'
    it will create DBNAME.sql file.
    but i want to run this command using java code
    i tried the following code but it did not work.
    is any other way is their?
    try {
                   Runtime.getRuntime().exec("setxkbmap nudi");
              } catch(IOException ioe) {
                   ioe.printStackTrace();
    thanks in advance
    daya

    hello,
    thanks for replay
    i am sorry the above code should be like this.(the above code is working fine)
    public class ExportTest{
         public ExportTest(){
              try {
                   Runtime.getRuntime().exec("mysqldump test > '/root/DBNAME.sql'");
              } catch(IOException ioe) {
                   ioe.printStackTrace();
              }catch(Exception e){
                   e.printStackTrace();
         public static void main(String args[]){
              new ExportTest();
    }when run above class, it not creating DBNAME.sql file.
    when run in command prompt it creating DBNAME.sql
    ($ mysqldump test > /root/DBNAME.sql)
    but i want to run this command from java code, that's way tried to do using above
    code, but it won't create DBNAME.sql
    is it wrong what i am doing? or any other way?
    thanks inadvace
    daya

  • Running unix command using java shows error

    Hi All,
    I am trying to run UNIX move command using Java exec method but its throwing error, unable to rename. Here below is the code i am trying to run to move all files from one directory to another directory. source and destination directory exists.
    public class Demo
        public static void main(String args[])
            try
                Runtime rt = Runtime.getRuntime();
                Process proc = rt.exec("mv /home/demo1/* /home/demo2");
                int exitVal = proc.waitFor();
                System.out.println("Process exitValue: " + exitVal);
            } catch (Throwable t)
                t.printStackTrace();
    }if i give "mv /home/demo1 /home/demo2" in exec method, its working, with * character its giving problem.
    Please help me in resolving the problem.
    Thank you

    Characters like *, >, &, |, etc. are interpreted by the command shell--that is by the bash, zsh, etc. programs. When you execute a command with ProcessBuilder or Runtime.exec, you're not going through one of those shells, so their interpretation of those characters is not available.
    In your code, the character * is being delivered directly to the mv command (which doesn't think * is anything special), as opposed to being turned into a list of files and directories as it would be when it's interpreted by the shell. The mv command doesn't know anything about the * character being special.
    If you want to have those shell interpretations, you need to execute the command through a shell. One example is like so, but a) you'll want to read up on the methods in exec() that take arrays of String, and b) you'll want to read up on ProcessBuilder, and c) you'll need to check your shell's man pages to see the exact syntax and arguments.
    runtime.exec("/bin/bash -c 'mv x/* y'");

  • Problem in running system commands using Runtime()

    hi,
    i am trying to run the "dir" command in windows OS using Runtime(). But while
    executing the program i am getting
    java.io.IOException: CreateProcess: dir error=2 error. But if i replace the "dir" command by "notepad" command its working fine. below is the source code.
    class testing
    public static void main(String args[])
         try{
    Runtime rt=Runtime.getRuntime();
    Process p=rt.exec("dir"); //Generating Errors
    //Process p=rt.exec("notepad"); //Working Fine
         }catch(Exception e){System.out.println(e);}
    }plzz help me out.
    thanx

    thats fine its working. i made two changes. First i used an array to send the
    arguments. if we directly use "cmd.exe /c dir" then its converting "/C" to "\C" thus
    producing the error. so i used
    Runtime rt=Runtime.getRuntime();
    String args1[]={"cmd.exe","/C","dir"};
    Process p=rt.exec(args1);But then i got no error no output. From other forums i came to know about capturing the data using input streams and i included the following code.
    BufferedReader Resultset = new BufferedReader
         (new InputStreamReader(p.getInputStream()));
    String line;
    while ((line = Resultset.readLine()) != null)
         {          System.out.println(line);          }Now its working fine. Thanx for ur help.

  • Running System commands using Runtime.exec()

    I'm trying to run an example from "The Java Programming Language" book by Arnold, Gosling and Holmes. I'm trying to run a system level command and get the results. The code looks like:
    public static String[] runCommand(String cmd) {
    String[] outputData= null;
    String[] cmdArray = {"/usr/bin/ls", "-l", "/tmp"};
    try {
    Process child = Runtime.getRuntime().exec(cmdArray);
    InputStream in = child.getInputStream();
    InputStreamReader reader = new InputStreamReader(output);
    BufferedReader = new BufferedReader(reader);
    // read the commands output
    int counter = 0;
    String line;
    while ((line = input.readLine()) != null)
    outputData[counter++]= line;
    if (child.waitFor() != 0){  // error when it's not 0       
    System.out.println("Couldn't run the command.");
    System.out.println("It produced the following error message : " + child.exitValue());
    outputData = null;
    } catch (Exception e){
    System.out.println("It got here!");
    System.out.println("It produced the following error message : " + e.getMessage());
    outputData = null;
    return outputData;
    It gets to the while line, trys to run the input.readLine() and kicks out the exception that looks like:
    It got here!
    It produced the following error message : null
    I know it gets to the input.readLine() because I had a whole lot more try blocks in there, but for simplicity left it out (so it look like the code in the book, which I tried originally). When I run the same command from the command line (on our Sun Solaris 2.8 system) I get results back. I'm not sure what I'm doing wrong. Any help would be greatly appreciated. Thanks.

    Hi, duffymo, hope you can help me. Consider this servlet code:
    String theCommand = "csh /export/home/gls03/sasstuff/runsas.csh /export/home/g
    ls03/sasstuff/gary2.sas";
    //Create a parent Process for the sas program subprocess:
    Process p = rt.exec(theCommand);
    System.out.println("after call to rt.exec(theCommand)");
    Here is the runsas.csh script:
    #!/bin/csh
    setenv LD_LIBRARY_PATH /opt/sybase/lib:/usr/lib:/usr/openwin/lib:/opt/SUNWspro/S
    C2.0.1
    setenv SASROOT /usr/local/CDC/SAS_8.2
    setenv XKEYSYMDB /usr/local/CDC/SAS_8.2/X11/resource_files/XKeysymDB
    $SASROOT/sas -sasuser /hpnpages/cgi-bin/applinks/hospcap/tmp $1
    The execution never gets to the println statment, here is the error:
    class java.io.IOException Exception. Message: CreateProcess: csh /export/home/g
    ls03/sasstuff/runsas.csh /export/home/gls03/sasstuff/gary2.sas error=2
    java.io.IOException: CreateProcess: csh /export/home/gls03/sasstuff/runsas.csh /
    export/home/gls03/sasstuff/gary2.sas error=2
    at java.lang.Win32Process.create(Native Method)
    at java.lang.Win32Process.<init>(Win32Process.java:66)
    at java.lang.Runtime.execInternal(Native Method)
    at java.lang.Runtime.exec(Runtime.java:551)
    at java.lang.Runtime.exec(Runtime.java:477)
    at java.lang.Runtime.exec(Runtime.java:443)
    at sasRunnerNew.doPost(sasRunnerNew.java:103)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
    pl.java:262)
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:21)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.ja
    va:27)
    at us.ny.state.health.hin.hinutil.HinFilter.doFilter(HinFilter.java:124)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.ja
    va:27)
    at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe
    rvletContext.java:2643)
    at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm
    pl.java:2359)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
    The command runs fine in unix.
    I've also tried using these as arguments to exec:
    String theCommand = "/bin/csh /export/home/gls03/sasstuff/runsas.csh /export/home/gls03/sasstuff/gary2.sas";
    String[] theCommand = {"csh", "/export/home/gls03/sasstuff/runsas.csh", "/export/home/gls03/sasstuff/gary2.sas"};
    These generate the same error. I'm thinking this is a sas-specific problem.
    Thanks for any help. Gary

  • Running Dos Command using Java

    How do i run a particular Dos command using a simple java class?

    Process process = Runtime.getRuntime().exec( ... );
    Search the forum. There are plenty of examples.

  • Running OS command using DBMS_PIPE

    Hi,
    I have reproduce the exemple in the documentation DBMS_PIPE - Example 3: Execute System Commands using the proc daemon.pc. It works, the commands are getting executed, but I have no control over them. What I need is for the calling PL/SQL function to wait for the OS command to finnish before continuing with the execution the PL/SQL function.
    Any hint would be appreciated. Thanks.

    odie_63 wrote:
    Justin Cave wrote:
    The normal way to approach that sort of requirement would be to use a Java stored procedure.Or a DBMS_SCHEDULER external program with "use_current_session" set to true.
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_sched.htm#i1013568
    On 10g+ I'd definitely give this a go.

  • To run a command using java code

    hi all,
    There is a command
    "java -jar selenium-server.jar -interactive"
    which i am running through command prompt after going to D:\MyFolder\Examples .
    i want to execute this command using java code .please help

    subratjyetki wrote:
    please answer in detail or if posible can u give the code for thisThe detail is given in the reference. Why don't you read it?
    I could give you the code but it will cost you ?100 per hour.

  • Deploy wsp through Power Shell- start stop SP admin service and run execadmsvcjobs command using power shell

    Hi,
     Can anyone pls point me any link/ src code  for  deplyoing wsp using power shell. I know I can deploy it through Add-spsolution and install-spsolution, the issue is that, it will give   "status - stuck in deploying scheduled..."
    and i need to restart the sharepoint services - services.msc --> SP administration and timer services - and then i need to run the exceadmsvcjobs command to deploy / update the wsp  successfully in solution store.
    i mean, whats the power shell equivalent of these tasks. or anyone has already scripted these.
    if i elaborate little bit, would like to know how to automatically Retract, Remove, Add and Deploy SharePoint 2010 WSP Solution Files with PowerShell

    ok, i have found  the same :
     here its : hope this will help someone.
    function wait4timer($solutionName)
    $solutionName ="TestingWSP.wsp"
    $solution = Get-SPSolution | where-object {$_.Name -eq $solutionName}
    if ($solution -ne $null)
    Write-Host "Waiting to finish soultion timer job" -ForegroundColor Green
    while ($solution.JobExists -eq $true )
    Write-Host "Please wait...Either a Retraction/Deployment is happening" -ForegroundColor DarkYellow
    sleep 5
    Write-Host "Finished the solution timer job" -ForegroundColor Green
    try
    # Get the WebApplicationURL
    $MyWebApplicationUrl = "http://srvr:21778/";
    # Get the Solution Name
    $MywspName = "TestingWSP.wsp"
    # Get the Path of the Solution
    $MywspFullPath = "D:\myWorkspace\TestingWSP.wsp"
    # Try to get the Installed Solutions on the Farm.
    $MyInstalledSolution = Get-SPSolution | Where-Object Name -eq $MywspName
    # Verify whether the Solution is installed on the Target Web Application
    if($MyInstalledSolution -ne $null)
    if($MyInstalledSolution.DeployedWebApplications.Count -gt 0)
    wait4timer($MywspName)
    # Solution is installed in atleast one WebApplication. Hence, uninstall from all the web applications.
    # We need to unInstall from all the WebApplicaiton. If not, it will throw error while Removing the solution
    Uninstall-SPSolution $MywspName -AllWebApplications:$true -confirm:$false
    # Wait till the Timer jobs to Complete
    wait4timer($MywspName)
    Write-Host "Remove the Solution from the Farm" -ForegroundColor Green
    # Remove the Solution from the Farm
    Remove-SPSolution $MywspName -Confirm:$false
    sleep 5
    else
    wait4timer($MywspName)
    # Solution not deployed on any of the Web Application. Go ahead and Remove the Solution from the Farm
    Remove-SPSolution $MywspName -Confirm:$false
    sleep 3
    wait4timer($MywspName)
    # Add Solution to the Farm
    Add-SPSolution -LiteralPath "$MywspFullPath"
    # Install Solution to the WebApplication
    #Install-SPSolution -Identity <SolutionName> -WebApplication <URLName> [-GACDeployment] [-CASPolicies]
    install-spsolution -Identity $MywspName -WebApplication $MyWebApplicationUrl -GACDeployment #-FullTrustBinDeployment:$true -GACDeployment:$false -Force:$true
    # Let the Timer Jobs get finishes
    wait4timer($MywspName)
    Write-Host "Successfully Deployed to the WebApplication" -ForegroundColor Green
    catch
    Write-Host "Exception Occuerd on DeployWSP : " $Error[0].Exception.Message -ForegroundColor Red
    ref :
    http://www.sharepointpals.com/post/How-to-Deploy-a-SharePoint-2013-Solution-(WSP)-in-the-Farm-using-PowerShell

  • Running OS command using OEM 11gR1

    Hi,
    I have installed OEM 11gR1 on linux 64bit machine and have applied all recommended patches on top of it. Everything worked out fine till i got to the part of configuring my database alert.
    Database Instance: UAT > All Metrics > Tablespace Space Used (%) > Tablespace Name APPS_UNDOTS1 >
    Jun 14, 2012 1:31:38 PM User Action SYSTEM SYSMAN initiated a manual reevaluation of the alert.
    Jun 8, 2012 1:13:36 PM Corrective Action <SYSTEM> Execution created for Corrective Action INITIATE_SMS.
    Jun 8, 2012 1:13:36 PM Corrective Action <SYSTEM> Another Corrective Action INI not run since there is an existing running execution of CA INITIATE_SMS.
    Jun 8, 2012 12:50:05 PM <SYSTEM> Tablespace APPS_UNDOTS1 is 98 percent full
    Jun 8, 2012 12:40:05 PM <SYSTEM> Tablespace APPS_UNDOTS1 is 91 percent full
    Based on some tablespace criteria i want the system to:
    1) generate a corrective action which is not happening (note that on line 2 above it seems like a corrective action was initiated but i don't know how this happened and this is the only occurrence)
    2) run an OS command when the alert is initiated to
    Questions:
    1) why is the system not generating any corrective actions
    2) how can i set OEM to run an OS command
    Thank you for your help

    odie_63 wrote:
    Justin Cave wrote:
    The normal way to approach that sort of requirement would be to use a Java stored procedure.Or a DBMS_SCHEDULER external program with "use_current_session" set to true.
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_sched.htm#i1013568
    On 10g+ I'd definitely give this a go.

  • Run dos command that starts program and program stay open

    I'm running the following code,
    string m_file= "c:\program\program.exe" ;// runs a program
    Process myProcess = new Process();
    myProcess.StartInfo.FileName = @programtextBox.Text.Trim();
    myProcess.StartInfo.Arguments = m_file;
    String m_arguments = myProcess.StartInfo.Arguments.ToString().Trim();
    myProcess.Start();
    It works fine except I need the program to stay open that this command starts. But it closes while it's in the process of starting.

    I had a mistake in what I posted in my code. Here it is again with corrections, and more detail.
    string m_run= "c:\my programs\adobe\photoshope.exe" //This is saved in the program and can be set to any program the user wants to use. it's saved in the programtextBox.Text noted eailer, which is saved to the hard drive.
    string m_file= "c:\file\anypicture.jpg" ;// picture that is selected in the interface.
    Process myProcess = new Process();
    myProcess.StartInfo.FileName = m_run;
    myProcess.StartInfo.Arguments = m_file;
    String m_arguments = myProcess.StartInfo.Arguments.ToString().Trim();
    myProcess.Start();
    This is a windows form program.
    It looks to me like you're either redacting or modifying your actual code before posting.  I could be wrong about that, but I'm pretty sure because:
    If you were calling Process.Start() against program files/adobe/photoshope.exe I believe that you'd get a Win32 Exception since I don't think that file exists in any photoshop installation.
    I sincerely doubt that you're actually working with "file/anypicture.jpg."
    I'm confused by the declaration of m_arguments which is never used.  I assume it is in fact used somewhere in your code.
    Finally, you have stated that the program to open files with is pre-defined, so I suspect that data is actually being pulled from a variable instead of from a hard string as in your "example."
    If that's the case then you might as well go shoot yourself in the foot, since that would do exactly as much good as asking for help with broken code and then posting pseudo-code instead of what doesn't work.  It's like telling an auto mechanic your
    car dies every time you hit 22 miles per hour, while delivering your bicycle for service.
    Content Removed

  • Running System Commands using Java

    HI,
    I am developing an application using java which requires some system commands to be run.For example i have to write a java function which can program the windows scheduler to run a particular executable at some time & another one to initiate an ftp.I however do not know how to execute the corresponding commands from java.Is there any way or some specific api(similar to the system command in c) that i can use to perform these operations.I am using j2sdk 1.4.0_01 on a win 98 machine to develop the application.

    See [url http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html]java.lang.Runtime

  • Problem in running Linux command using JavaRuntine

    All,
    When I ran a Linux command in Java Program It does not give a correct output instead it returns null string.
    When I ran the Qsub command( as given in the below program) in Java program I suppose to get Unable to run job: unknown resource "mechhpc1".Exiting. as an output. But it returns null string. It works fine in linux terminal.
    Can you please anyone help me to fix this issue?
    Regards,
    Thamizhannal P
    Source code:
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    public class QSubCmdTest {
         static String Qsub = "sudo -u tce qsub -S /bin/bash ansys_p3 "
                   + "-pe Parallel 3 -l h_rt=3:4:4,ansys=0.333,mechhpc1=0.333 "               
                   + "-a 0804081247.15 /home/tce/c1p4/AnsysParallel";
    /* The aboove command output in terminal (linux machine)
    Unable to run job: unknown resource "mechhpc1".Exiting. */
         static String QSUBcommandOutput = "";
         public static void main(String[] args) {
              System.out.println("Job Submission testing");
              try {
                   Process processExecGenericJobScript = Runtime.getRuntime().exec( new String[]{"/bin/bash","-c",Qsub});
                   //QSUB Command output Reader
                   BufferedReader QSUBcommandOutputReader = new BufferedReader(
                             new InputStreamReader(processExecGenericJobScript
                                       .getInputStream()));
                   System.out.println("Reader "+QSUBcommandOutputReader.readLine());
                   //QSUB command output string
                   String QSUBCommandOutputString = "";
                   while ((QSUBCommandOutputString = QSUBcommandOutputReader
                             .readLine()) != null) {
                        QSUBcommandOutput += QSUBCommandOutputString;
                        QSUBcommandOutput += "\n";
                   System.out.println("QSUBcommandOutput:" + QSUBcommandOutput);
              } catch (Exception exp) {
                   exp.getMessage();
    }

    I would expect error messages to be output on stderr not stdout and you only read stdout. You should read, digest and implement the recommendations in http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html .

Maybe you are looking for

  • How to cancel the GR after UD

    Hi i have created a GR (migo) and in this step i have also captured the excise invoice. QC people done the UD. after that i came to know that GR is wrong. now i want to cancel the GR. and make the new GR against the same PO. Thanks & Regards Pankaj G

  • I updated itunes and have bow lost all my itunes library

    I updated itunes last night and today I have no songs/albums in my library! Please can someone tell me how to restore my itunes library?

  • Drag & Drop, ALV or Table Control to Tree Control

    Hi Experts, If i want Drag & Drop feature in ALV or Table Control to Tree Control

  • Serialization on os x returns (SIGTRAP)

    Hello everyone! I'm writing an os x application that calculates scores for a local swim team, and then stores them along with other information about swimmers and the team. I'm using apple's appkit, a series of java classes meant to work with their I

  • Measure period and pulse duration of ttl level continuously

    Hello, i want measure the period and pulse duration continuously of two signals with an usb-6009. Every 8s there is a high pulse for 15ms. I want to measure length of the pulse and  pause. Can someone help me? I can`t get a start up with this problem