I've a problem with my EXE file, generated by Matlab Development tool.
Pratically, even choosing "Windows StandAlone Mode", when I run the EXE, always appears the hated black CMD console.
How can I avoid this apparition?
Thanks for the help to everyone who Try...
There is a utility published on the Mathworks website that does just that. http://www.mathworks.com/matlabcentral/fileexchange/3909-suppress-command-window
Another solution would be to use another application to launch your MATLAB exe silently.
In C# for example you could start your MATLAB exe with the following arguments to hide the console window:
var process = new Process();
process.StartInfo.FileName = "path to your exe"
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
// ...
process.Start();
Related
I have made EXE File using pyinstaller, and option is
pyinstaller ams.py -w -F --icon=icon.ico --add-binary "IEDriverServer.exe";"." --noconsole.
And python code is,
if getattr(sys, 'frozen', False):
IEdriver_path = os.path.join(sys._MEIPASS, "IEDriverServer.exe")
driver = webdriver.Ie(IEdriver_path)
And then start the EXE file,
"Temp_MEI175xxx\IEDriverServer.exe" console is made.
when I off that console, program is ended.
Is there a way to hide console window?
I have created a small program in Visual Studio - a form with a button to execute the program when clicked - and built the .exe.
This program is supposed to open PowerShell and run a ps1 file.
When I run it from within VS in debug mode, it works as expected running the ps1 script without error.
When I build the project and run the exe as an administrator, it briefly opens PowerShell but closes immediately.
The output file states that the execution of scripts is disabled on this system, although this is incorrect as I can run any number of PowerShell scripts manually by right clicking them and running them with PowerShell.
I have tried changing the execution policy from Signed, to AllSigned, as well as Unrestricted, but it did not help.
Here is my code:
if (File.Exists("LiveSiteTests.ps1"))
{
File.GetAttributes("LiveSiteTests.ps1");
string strCmdText = Path.Combine(Directory.GetCurrentDirectory(), "LiveSiteTests.ps1");
var process = new Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.FileName = #"C:\windows\system32\windowspowershell\v1.0\powershell.exe";
process.StartInfo.Arguments = "\"&'" + strCmdText + "'\"";
process.Start();
string s = process.StandardOutput.ReadToEnd();
process.WaitForExit();
using (StreamWriter outfile = new StreamWriter("StandardOutput.txt", true))
{
outfile.Write(s);
}
}
Is there a way of running a MATLAB script from Notepad++?
Obviously I have MATLAB installed on my computer. I know you can set a path for Notepad++to run when you hit F5, but when I set this path to my MATLAB.exe file, it simply opens another instance of MATLAB.
This is not what I want, I want the actual script in Notepad++ to be executed in the already open and running instance of MATLAB.
I'm afraid I'm not on my home computer at the moment to test this out, so the following is just a suggestion for you to try.
If you take a look at the NppExec plugin for Notepad++, you'll see that with it you can specify a command to be run when you hit F6 (like an enhanced version of hitting F5 in the regular Notepad++). You can also give it variables such as the path to the current file, and the name of the current file.
MATLAB (on Windows at least - I assume you're on Windows) makes available an API over ActiveX/COM. If you search in the MATLAB documentation for details, it's under External Interfaces -> MATLAB COM Automation Server. By running (in MATLAB) the command enableservice('AutomationServer') you will set up your running instance of MATLAB to receive instructions over this API.
You should be able to write a small script (perhaps in VBScript or something similar) that will take as input arguments the path and filename of the current file in Notepad++, and will then connect to a running instance of MATLAB over the COM API and execute the file's contents.
Set this script to be executed in NppExec when you hit F6, and it should then run the current file in the open instance of MATLAB.
As I say, the above is just speculation as I can't test it out right now, but I think it should work. Good luck!
Use NppExec add-on and press F6, copy paste the following and save the script:
NPP_SAVE
set local MATPATH=C:\Program Files\MATLAB\R2015a\bin\matlab.exe
cd "$(CURRENT_DIRECTORY)"
"$(MATPATH)" -nodisplay -nosplash -nodesktop -r "try, run('$(FILE_NAME)'),
catch me, fprintf('%s / %s\n',me.identifier,me.message), end"
then run (press F6; enter). Matlab Console and Plot windows still open and stay open. Error messages will be displayed in opening Matlab command window. Adding
, exit"
to the last command will make it quit and close again. If you want to run an automated application with crontabs or the like, check Matlab external interface reference for automation.
matlab.exe -automation ...
Also works in cmd terminal, but you have to fill in the paths yourself.
This is a usable implementation upon Sam's idea. First, execute MATLAB in automation mode like this.
matlab.exe -automation
Next, compile and execute this following VB in NppExec plugin. (which is to use MATLAB automation API)
'open_matlab.vb
Imports System
Module open_matlab
' connect to a opened matlab session
Sub Main()
Dim h As Object
Dim res As String
Dim matcmd As String
h = GetObject(, "Matlab.Application")
Console.WriteLine("MATLAB & Notepad++")
Console.WriteLine(" ")
'mainLoop
while True
Console.Write(">> ")
matcmd = Console.ReadLine()
' How you exit this app
if matcmd.Equals("!!") then
Exit while
End if
res=h.Execute(matcmd)
Console.WriteLine(res)
End while
End Sub
End Module
Then you'll get a matlab-like terminal below your editor. You can then code above and execute below. type !! to exit the terminal.
What it looks like
Tips: don't use ctrl+c to interrupt the MATLAB command, because it will kill the whole process instead.
I have a very simple VBScript file that interacts with iTunes via a COM object:
If I double-click on the .vbs file, it works fine. But if I run it from the command line, it fails:
c:\windows\SysWOW64\wscript myscript.vbs
iTunes opens, but the commands don't work, and after a short delay I get this:
ActiveX component can't create object: 'iTunes.Application'
Code: 800A01AD
The problem remains when I use cscript, and when I use the system32 version.
So, two questions:
Why is the behaviour different when double-clicking/running from the CLI?
How do I fix it, so it runs from the CLI, too?
Edited to add script:
Dim oiTunes, oTracks, oAdd
Set oiTunes = CreateObject("iTunes.Application")
Set oTracks = oiTunes.LibraryPlaylist
Set oAdd = oTracks.AddFile("D:\Users\Mark\Music\Downloaded iPlayer\Temp\temp.mp4")
Do : Loop While oAdd.InProgress = True
Set oAdd = Nothing
Set oTracks = Nothing
Set oiTunes = Nothing
The script you have shared works fine for me. Perhaps one of the CSLIDs has become corrupt - try reinstalling or repairing iTunes.
I have a executable that when double clicked opens in a command line window.
Now there is a input file (i.e named "sphere_15000.inp") in the same directory where the executable apame_win64.exe is located. So we can inter the file name in the command line.
The question is how this can be done from mathematica front end? With the RunThrough command I tried to do it with no avail.
RunThrough["Executable Location", "sphere_15000"]
Do I need to put this file location in my Windows 7 environment path variable? Hope for some suggestion in this regard.
UPDATE
Found a solution to my problem.
First set the Mathematica directory to the folder where the executable is located.
path="C:\Users\FlowCrusher\Desktop\CUSP solver\Apame_build_2011_01_09\solver";
SetDirectory[path];
Then use the following style of input.
Run["\"\"apame_win64.exe\" \"input\"\""]
Here "apame_win64.exe" is the executable one want to run and "input" is the input file for the executable. This solves the problem. But a new item in the wishlist.
Is there a way to hide the console window in the background?
Here is how it looks on my screen.
As Chris suggested if we use minimized console in the Run command we get a minimized window but the program does not execute.
I hope that a solution exists.
BR
Yes, you might put the folder of you executable into the Path variable, or provide the full path name.
However, RunThrough seems to have been superseeded (on Windows) by
Import["!command ","Text"], which will execute command and read the comaand line output into Matheamtica as a string.
E.g.:
Export["testit.txt", "bla", "Text"];
Import["!dir" <> " testit* > dir.log", "Text"];
FilePrint["dir.log"]
--
Otherwise, I also had good results in the past using NETLink (not sure if WScript.shell
still works on Windows7/8 or if one should use something else).
Emulating Run (RunThrough is not really needed I think):
Run2[cmd_String] := Module[{shell},
Switch[$OperatingSystem,
"Windows",
Needs["NETLink`"];
shell = NETLink`CreateCOMObject["WScript.shell"];
shell # run[cmd,0,True],
"Unix",
Run # cmd,
"MacOSX",
Run # cmd ] ];
Can you run your application with input from a basic command window instead of the application console? This might be the form of command you would need:
apame_win64 -input sphere_15000.inp
or simply
apame_win64 sphere_15000.inp
You can probably check the available switches by running apame_win64 -help
A multi-part command can be run from Mathematica, e.g.
Run["type c:\\temp\\test.txt"]
Alternatively, also returning output to the Mathematica session:
ReadList["!type c:\\temp\\test.txt", String]
I landed here wanting to run abaqus command line on windows.
The solutions provided here worked out for me (Windows 7, Mathematica 9):
SetDirectory#path;
Run["start /min abaqus job=" <> fileName <> " interactive ask_delete=OFF >> log.txt"]
(Here the abaqus option ask_delete=OFF overwrites an existing simulation results and the >> redirects all the output to a file)
I think, minimizing the window did not run in your case since the executable throws open that window. In that case, this might be of some help