You will need access to the remote machine to do this. Deleting and Renaming remote files are incredibly useful tools when you are doing deployment, integration and configuration testing. You can tweak aspects of the deployed system just before test time to create desired scenarios. All in an automated way.
First up, deleting a file locally.
void DeleteFile (const char* const filename)
{
lr_set (filename, "__DeleteFile_filename") ;
system ("del /S /Q {__DeleteFile_filename}") ;
}
Yay! That was easy. Now we should delete a remote file. This just a simple process of creating a batchfile, xcopying it to the server and then using psexec to run it.
void DeleteRemoteFile (const char* const filename)
{
//Create batch file
long FileHandle = 0 ;
lr_set (filename, "__RenameFile_filename") ;
FileHandle = fopen("del.bat", "w") ;
if (!FileHandle)
{
lr_error_message ("Unable to create the \"del.bat\" file.") ;
return
}
fprintf (FileHandle, lr_get ("del /S /Q {__RenameFile_filename}")) ;
fclose (FileHandle) ;
//Xcopy batch to remote
system (lr_get ("xcopy /Y /Q \"del.bat\" \\\\{Server}\\c$\\temp\\*")) ;
//psexec batch on remote
system (lr_get ("\"psexec.exe\" \\\\{Server} C:\\temp\\del.bat")) ;
}
And finally we can rename a remote file. Same process as above. Are you getting the pattern here>
void RenameRemoteFile (const char* const Path, const char* const OldFilename, const char* const NewFilename)
{
//Create batch file
long FileHandle = 0 ;
lr_set (Path, "__RenameFile_Path") ;
lr_set (OldFilename, "__RenameFile_OldFilename") ;
lr_set (NewFilename, "__RenameFile_NewFilename") ;
FileHandle = fopen("ren.bat", "w") ;
if (!FileHandle)
{
lr_error_message ("Unable to create the \"ren.bat\" file.") ;
//return Result ;
}
fprintf (FileHandle, lr_get ("ren {__RenameFile_Path}{__RenameFile_OldFilename} {__RenameFile_NewFilename}")) ;
fclose (FileHandle) ;
//Xcopy batch to remote
system (lr_get ("xcopy /Y /Q \"ren.bat\" \\\\{Server}\\c$\\temp\\*")) ;
//psexec batch on remote
system (lr_get ("\"psexec.exe\" \\\\{Server} C:\\temp\\ren.bat")) ;
}
When I wrote these functions I wanted to only build dependencies on applications that already existed in the environment. This is why I use batch files, xcopy and psexec. The secondary goal was to get the functions written with as little effort as possible.
|
|
Ryan Boucher is a Software Inquisitor and is passionate about it. You can find a whole raft of articles and anecdotes about software testing and other topics he gets excited about. |
| Tags |