After writing a file from AX, need to kick of a .cmd file to FTP it. Runs fine on client, but can't get it to work on server. For now I have server static method in a sandbox class, but eventually it will be submitted via RunBaseBatch. I've got code using System.IO.File::Exists, and that all appears to be working fine. For now I'm testing with a .cmd file that just renames a file based on command line parameters.
if (allGood)
{
try
{
// Run a .cmd file
perms = new Set(Types::Class);
perms.add(new InteropPermission(InteropKind::ClrInterop));
perms.add(new FileIOPermission(cmdExe, #io_read)); // C:\Windows\system32\cmd.exe
perms.add(new FileIOPermission(wrkPath + '\\' + testCmd, #io_read)); // mytest.cmd
perms.add(new FileIOPermission(wrkPath + '\\' + renFil1, #io_readwrite)); // tst.1
perms.add(new FileIOPermission(wrkPath + '\\' + renFil2, #io_readwrite)); // tst.2
process = new System.Diagnostics.Process();
processStartInfo = new System.Diagnostics.ProcessStartInfo();
processStartInfo.set_FileName(cmdExe);
processStartInfo.set_WorkingDirectory(wrkPath);
startArgs = '/C '
+ '\"' + wrkPath + '\\' + testCmd + '\" '
+ '\"' + wrkPath + '\" ' + renFil1 + ' ' + renFil2;
processStartInfo.set_Arguments(startArgs);
process.set_StartInfo(processStartInfo);
procStarted = process.Start();
process.WaitForExit(500);
}
catch (Exception::CLRError)
{
info(strfmt("CLR error occurred while executing the command file %1 in directory %2", testCmd, wrkPath));
sysExc = ClrInterop::getLastException();
while (sysExc)
{
info(sysExc.get_Message());
sysExc = sysExc.get_InnerException();
}
allGood = false;
}
}
CodeAccessPermission::revertAssert();
wrkPath is a UNC path with embedded spaces, so the start args need quotation marks.
When I run this, it returns immediately, and WaitForExit just continues, but the script hasn't been executed. The file isn't renamed. When I open a command window and type what I think is the same command line, cmd /C "\\server\path\mytest.cmd" "\\server\path" tst.1 tst.2, it does what I expect. It also works if I change the method to client.
Do I need some special permissions, or is it just not possible to run .cmd files on server? I've also tried using the .cmd file directly in set_FileName, and as .bat instead of .cmd. When I did those, the .start() just hangs (and I have to do a hard close of the rich client).
*This post is locked for comments