March 20, 200916 yr Hello ! I was looking for something like the Abstrakt's Shell 1.1 plugin that gives us access to some shell functions on Windows, but it does not seems available anymore and I can't find something else similar. The Run Event command does not give us back any output and do not wait the end of the command to proceed. So this is not an option for me. So anybody knows where I could get some free plugin for Windows for this, or do I need to write another one myself ? : Thanks ! Frankywinky
March 20, 200916 yr 360Works ScriptMaster will do this and any anything else (as long as you know how to say it in java) - even has it's own forum on this site. Edited March 20, 200916 yr by Guest
March 24, 200916 yr Author Hum, it looks great. Maybe it will do the work for now. Somehow, in my case, it is a little unreasonable to pass by Java to call a python script... Anyway, thank you for your suggestion !
July 17, 200916 yr I wrote a plug-in to do this recently, as a learning exercise. It's only for Windows. I can post it (source less the source copyrighted by FM), and/or executable) if there is any interest; it's probably only 30 or 40 lines of code. It uses the System::Diagnostics::Process .NET class. It accepts as parameters the filename (e.g., "cmd /c"), the command (e.g. "dir"), and a timeout in seconds. It returns the output from the console window. It works except for the timeout, that part needs some additional work. Also it currently returns only standard output (would also be nice to return an Errorlevel code, and standard error joined to standard output). How did the Abstrakt plugin handle this? I've used the Scriptmaster plugin and also send event methods. -Frank
July 17, 200916 yr Below is the source for a do shell plugin function accessible from Filemaker, for Windows in C++. It returns the standard output from the DOS command (e.g. directory listing, etc). It works but has two issues: 1.) It ignores timeout parameter; it would be nice if you could tell it to timeout, say, in 10 seconds. 2.) It currently does not return standard error to Filemaker; only standard output is returned. Perhaps these issues could be fixed & this function added, say, to MooPlug? It accepts command, arguments, timeout as its parameters, so: If you use ECS_SHELL("cmd.exe","/c dir C:",10) it will return a directory of C:. The ScriptMaster plugin example which runs a shell command also does not return standard error; however, you can remedy that by adding this line to concactenate standard error to its returned result: processResult = processResult + process.getErrorStream().getText(); (add line just before process.waitFor(); in ScriptMaster Run Shell Script example. I'm just beginning with C++ so this could probably be cleaned up, especially parameter conversions to strings. ------------------------------------------------ FMX_PROC(fmx::errcode) Do_ECS_Shell(short /* funcId */, const fmx::ExprEnv& /* environment */, const fmx::DataVect& dataVect, fmx::Data& results) { fmx::errcode errorResult = 0; // Set to zero to indicate no error (non-zero value causes Filemaker to ignore results returned from plugin) fmx::TextAutoPtr resultTxt; // Output from standard output is returned to Filemaker through this pointer char *sFileName=(char*)GlobalAlloc(GPTR, 255); // Convert first parameter passed to plugin (Filename) from type FMX to type String^ const fmx::Text& param1 = dataVect.AtAsText(0); // NOTE: 255 character limit on Filename param1.GetBytes((char*)sFileName,255); String^ stringFileName = gcnew String(sFileName); char *sArguments=(char*)GlobalAlloc(GPTR, 255); // Convert second parameter passed to plugin (Arguments) from type FMX to type String^ const fmx::Text& param2 = dataVect.AtAsText(1); // NOTE: 255 character limit on arguments param2.GetBytes((char*)sArguments,255); String^ stringArguments = gcnew String(sArguments); char *sTimeOut=(char*)GlobalAlloc(GPTR, 255); // Convert third parameter passed to plugin (Timeout) from type FMX to type integer const fmx::Text& param3 = dataVect.AtAsText(2); param3.GetBytes((char*)sTimeOut,255); String^ stringTimeOut = gcnew String(sTimeOut); int numeric_timeout_ticks = 0; numeric_timeout_ticks = Convert::ToInt32(stringTimeOut)*1000; // Below is code to run shell command ######################### System::Diagnostics::Process ^myProcess = gcnew System::Diagnostics::Process(); myProcess->StartInfo->FileName = stringFileName; // filename to run, e.g. for DOS command processor, 'cmd.exe' myProcess->StartInfo->Arguments = stringArguments; // arguments, e.g. for disc directory use '/c dir' where /c hides DOS Window myProcess->StartInfo->UseShellExecute = false; myProcess->StartInfo->CreateNoWindow = true; myProcess->StartInfo->RedirectStandardInput = true; // Redirects standard output from console (e.g. DOS) Window so it can be returned to Filemaker myProcess->StartInfo->RedirectStandardOutput = true; myProcess->StartInfo->RedirectStandardError = true; myProcess->StartInfo->WindowStyle=ProcessWindowStyle::Hidden; // Hide window myProcess->Start(); // Begin process StreamWriter ^sIn = myProcess->StandardInput; // Redirect standard input: not currently used, but could be used for dynamic scripted control of console from Filemaker StreamReader ^sOut = myProcess->StandardOutput; // Redirect standard output StreamReader ^sErr = myProcess->StandardError; // Redirect standard error: not currently used, but ought to be joined with standard input System::String ^s = sOut->ReadToEnd(); // Read standard output into a string myProcess->WaitForExit(numeric_timeout_ticks); // Wait for process to finish. e.g. 5000 ticks = 5 seconds. CString string_to_return(s); // Convert string to a form digestable by Filemaker sIn->Close(); sOut->Close(); myProcess->Close(); resultTxt->Assign(string_to_return); // Assign output and return to Filemaker results.SetAsText(*resultTxt,dataVect.At(0).GetLocale() ); return(errorResult); }
Create an account or sign in to comment