Thanks Sharon.

 

 

The old code is working by using the solution provided by you in the mail
'staf-users Digest, Vol 37, Issue 28'.

 

<Snip>

 

Try encapsulating the executable within double quotes within the command as 

follows.  Does that work on your machine?

 

C:\>STAF local PROCESS START COMMAND "\"C:\Testing\Bluetooth 

Test\Bluetooth Installer\afBluetooth_v1_0_1_Setup.exe\""

Response

--------

244

 

<End>

 

 

  _____  

From: Sharon Lucas [mailto:luc...@us.ibm.com] 
Sent: Tuesday, June 30, 2009 8:42 PM
To: sha...@acmet.com
Cc: staf-users@lists.sourceforge.net
Subject: Re: [staf-users] How to use DOS copy command through STAF if spaces
areexists in the path?

 


STAF provides some Java APIs for you to use as documented in the STAF Java
User's Guide at http://staf.sourceforge.net/current/STAFJava.htm.  One of
these is the wrapData() method in the STAFUtil class.  You should use that
within a Java program to "wrap" option values that contain spaces (so that
the STAF command parser knows when an option value that contains spaces
begins and ends) instead having lots of escaped backslashes. 

In addition, you need to understand that the Windows copy executable
requires that file paths containing spaces need to be enclosed in double
spaces so that it knows when a path begins and ends.  So, the actual copy
command you want STAF to run will be something like:   

  copy "C:\Documents and Settings\All Users\Documents\*.*" "C:\Documents and
Settings\All Users\Documents\a\*.*" 

Don't you want to use the "xcopy" command instead of the "copy" command?
Anyway, just be sure that the copy command you are really submitting is a
valid command (e.g. that it works when run via a command prompt without
STAF). 

And you will probably find it useful to use the RETURNSTDOUT and
RETURNSTDERR options on the STAF PROCESS START request to return the
command's stdout/stderr which may provide additional information when the
command fails. 

Also, it is helpful to print out the actual STAF PROCESS START request that
you submitted if it fails to see if you constructed the PROCESS START
request incorrectly. 

Also, you may want to use the STAF file separator variable
{STAF/Config/Sep/File} instead of specifying "\\". 

Here's some updated Java code for you to try:

 public boolean bCopy(String astrSourcePath, String astrDesPath)
{ 
     // Create a STAFHandle object used to submit STAF service requests
    STAFHandle lObjectOfSTAFHandle;

    // Create a STAFResult object to hold result from STAF command
    STAFResult lObjectOfSTAFResult;

    try
    {
        // Create a STAF handle 

        lObjectOfSTAFHandle = new STAFHandle("CopyFiles");

         // Create the DOS copy command for copying files 

         String sourceFiles = "\"" + astrSourcePath +
"{STAF/Config/Sep/File}*.*\""; 
         String desFiles = "\"" + astrDesPath +
"{STAF/Config/Sep/File}*.*\""; 
         String command = "copy " + sourceFiles + " " + desFiles; 
         String request = "START SHELL COMMAND " + 
             STAFUtil.wrapData(command) + 
             " RETURNSTDOUT RETURNSTDERR SAMECONSOLE WAIT"; 

        // Submit a STAF PROCESS START comamnd to copy files 

        lObjectOfSTAFResult = lObjectOfSTAFHandle.submit2( 
             "local", "PROCESS", request);

        if (lObjectOfSTAFResult.rc == 0)
        { 
             // Copy command worked 

            return true;
        }
        else
        {
            // Copy command failed 
             // Print additional error information provided by the 
             // DOS copy command in stdout/sdterr (which is returned 
             // in the result 

             System.out.println( 
                 "STAF local PROCESS " + request + 
                 " failed with RC=" + lObjectOfSTAFResult.rc + 
                 ", Result=" + lObjectOfSTAFResult.result); 

            return false;
        }
    }
    catch (STAFException aobjSTAFException)
    {
        // Print the exception on console 

        aobjSTAFException.printStackTrace(); 

        return false;
    } 
 } 

--------------------------------------------------------------
Sharon Lucas
IBM Austin,   luc...@us.ibm.com
(512) 286-7313 or Tieline 363-7313





"Shahid" <sha...@acmet.com> 

06/29/2009 07:23 AM 


Please respond to
sha...@acmet.com


To

<staf-users@lists.sourceforge.net> 


cc

 


Subject

[staf-users] How to use DOS copy command through STAF if spaces are
exists in the path?

 


 

 




I have written following code in java for using the DOS copy command through
STAF for copying files:

public boolean bCopy(String astrSourcePath, String astrDesPath)
   {
    
    astrSourcePath = astrSourcePath.replace("\\", "\\\\");
    astrDesPath = astrDesPath.replace("\\", "\\\\");

    //Creating object of STAFHandle
    STAFHandle lObjectOfSTAFHandle;

    //It is used to create an object of STAFResult which hold output of
STAF command
    STAFResult lObjectOfSTAFResult;

    try
    {
      //Creating STAF handle
      lObjectOfSTAFHandle = new STAFHandle("CopyFiles");

      //Executing the DOS command for copying files
      lObjectOfSTAFResult = lObjectOfSTAFHandle.submit2("LOCAL",
       "PROCESS", " START Shell COMMAND COPY PARMS \""+
        astrSourcePath+"\\\\*.*\"  \""+ astrDesPath+"\\\\*.*\" wait
SAMECONSOLE");

      //If files are copied successfully
      if(lObjectOfSTAFResult.rc == 0)
      {
       
       //returning the status of copying files as true
        return true;
      }
      //If files are not copied
      else
      {
        //returning the status of copying files as false
        return false;
      }

    }

    catch (STAFException aobjSTAFException)
    {
      //Printing the exception on consol
      aobjSTAFException.printStackTrace();

      //returning the status of copying files as false
      return false;
    }
   }

Above method are working fine, if spaces are not exists in the source path
and destination path.

Above method are not working in case of spaces exists in the source path of
destination path.

However after running following STAF command through command prompt, files
are copied in case spaces are exits in source path of destination path:

<Snip>

C:\>STAF LOCAL PROCESS START SHELL COMMAND COPY PARMS \""C:\Documents and
Settings\All Users\Documents\*.*"" \""C:\Documents and Settings\All
Users\Documents\a\
*.*"" wait sameconsole
Response
--------
{
 Return Code: 0
 Key        : <None>
 Files      : []
}

C:\>

<End>

I have modified the java code with the following code:



public boolean bCopy(String astrSourcePath, String astrDesPath)
   {
    
    astrSourcePath = astrSourcePath.replace("\\", "\\\\");
    astrDesPath = astrDesPath.replace("\\", "\\\\");

    //Creating object of STAFHandle
    STAFHandle lObjectOfSTAFHandle;

    //It is used to create an object of STAFResult which hold output of
STAF command
    STAFResult lObjectOfSTAFResult;

    try
    {
      //Creating STAF handle
      lObjectOfSTAFHandle = new STAFHandle("CopyFiles");

      //Executing the DOS command for copying files
      lObjectOfSTAFResult = lObjectOfSTAFHandle.submit2("LOCAL",
       "PROCESS", " START Shell COMMAND COPY PARMS \\\"\""+
        astrSourcePath+"\\\\*.*\"\"  \\\"\""+ astrDesPath+"\\\\*.*\"\" wait
SAMECONSOLE");

      //If files are copied successfully
      if(lObjectOfSTAFResult.rc == 0)
      {        
       //returning the status of copying files as true
        return true;
      }
      //If files are not copied
      else
      {
        //returning the status of copying files as false
        return false;
      }
    }

    catch (STAFException aobjSTAFException)
    {
      //Printing the exception on consol
      aobjSTAFException.printStackTrace();

      //returning the status of copying files as false
      return false;
    }
   }

But still it is not working.

Can anyone tell me what is the problem in the code?


----------------------------------------------------------------------------
--
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users

------------------------------------------------------------------------------
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users

Reply via email to