How i can run a script outside from standalone application made in matlab? - matlab

I have a standalone app in matlab. It gets a file name as an input and need to run this file.
The file is on the same path as the standalone app.
thx,
Mike.

You can use the -a option to compile additional files.
For instance, with this command you'll be able to call any .m file in your current directory from your standalone application:
mcc -m myscript.m -a *.m

It sounds like you're looking for the SYSTEM function. You can pass it any variable as a string:
s = 'ls'; % use 'ls' for Mac/Unix, 'dir' for Windows
[status, result] = system(s);
Here status is the OS status code (0 means the program exited without error), and result is the output of the program:
>> status
status =
0
>> result
result =
total 928
-rw-r--r-- 1 stew stew 0 Jul 24 2009 PROJECT_BASE
drwxr-xr-x 48 stew stew 1632 Mar 17 2011 analysis
-rw-r--r-- 1 stew stew 1944 Oct 4 2010 diff1
drwxr-xr-x 29 stew stew 986 Sep 24 2011 matlab
drwxr-xr-x 11 stew stew 374 Aug 5 2009 matlab_old
-rw-r--r-- 1 stew stew 62525 Jul 6 2010 nms.mat
-rw-r--r-- 1 stew stew 111423 Jul 7 2010 nms1.mat
drwxr-xr-x 52 stew stew 1768 Mar 2 2010 p60_analysis
drwxr-xr-x 4 stew stew 136 Mar 26 23:08 sims
-rw-r--r-- 1 stew stew 2212 Jan 29 2010 startup.m
-rw-r--r-- 1 stew stew 264635 Jun 13 18:22 test.bundle
-rw-r--r-- 1 stew stew 128 Sep 24 2010 testlatt.m
-rw-r--r-- 1 stew stew 4618 Jun 15 2011 tt-conn-ERRSTATE.mat
-rw-r--r-- 1 stew stew 6221 Jun 13 17:50
update_2012_June_13.bundle
drwxr-xr-x 4 stew stew 136 Jun 13 18:28 videos
NB: If the program is not on your executable path, you may need to specify its absolute path:
s = '/usr/bin/ls';
[status, result] = system(s);

I think I asked exactly a similar question and could not get an answear.
Is it possible to execute compiled code both within and out of MATLAB environment?
I believe it is not possible as Mathworks doesn't want you to distribute a free Matlab interpreter. I wonder if one can compile two set of M files separately and run the second from the first as a workaround.

Related

How to really see the contents of the different perl scripts linking to one file?

I wanted to view the contents of a perl script in our environment which is called dfv_run.pl and specifically check line 245. Line 245 from that script printed the message "Finished checking test result" in my simulation log file. After executing % which dfv_run.pl I am pointed to this location:
drwxr-xr-x 2 dfvmgr dfvadmin 4.0K Jun 22 2017 .SYNC
-r--r--r-- 1 dfvmgr dfvadmin 3.2K Jun 22 2017 loadenv.csh
-r-xr-xr-x 1 dfvmgr dfvadmin 5.2K Jun 22 2017 loadenv
drwxr-xr-x 4 dfvmgr dfvadmin 4.0K Jun 22 2017 ..
drwxr-xr-x 3 dfvmgr dfvadmin 4.0K Jun 22 2017 .
lrwxrwxrwx 1 dfvmgr dfvadmin 7 Jun 22 2017 dfv_comp.pl -> loadenv
lrwxrwxrwx 1 dfvmgr dfvadmin 7 Jun 22 2017 dfv_run.pl -> loadenv
lrwxrwxrwx 1 dfvmgr dfvadmin 7 Jun 22 2017 dfv_sim.pl -> loadenv
/tools/dfv/scripts/v11/bin
However the script is only less than 200 lines and I can see the same content for dfv_comp.pl, dfv_run.pl, and dfv_sim.pl (also diff did not show any difference among the 3 perl scripts). loadenv of course also showed me the same contents.
Any help as to how I can view the real content of each perl script is much appreciated. Additional info which might help:
SHELL=/bin/tcsh
KONSOLE_DBUS_SERVICE=:1.46
KONSOLE_DBUS_WINDOW=/Windows/17
KONSOLE_DBUS_SESSION=/Sessions/30
Kindly let me know if additional info is needed. Thank you in advance!
What you're seeing is the real content. All three *.pl filenames are aliases to the loadenv script - that one script handles all four commands.
If you look at the contents of loadenv (or any of the other three names), you will most likely see that it checks to see which name was used to invoke it and then sets some flags which will cause it to behave differently depending on which name was used.

How To Launch WinGDB GUI Outside of Visual Studio?

If I look at the installation directory I see:
mhoggan#1USDMHOGGAN /cygdrive/c/Program Files (x86)/SoftErg/WinGDB
$ ls -l
total 19620
drwxrwx---+ 1 SYSTEM SYSTEM 0 Jan 26 11:00 1033
drwxrwx---+ 1 SYSTEM SYSTEM 0 Jan 26 11:00 Generators
-rwxr-x---+ 1 SYSTEM SYSTEM 583168 Jan 10 13:51 softergCrashReporter.exe
-rwxr-x---+ 1 SYSTEM SYSTEM 59392 Jan 10 13:52 softergProcessBreaker64.exe
-rwxr-x---+ 1 SYSTEM SYSTEM 546816 Jan 10 13:51 softergShell.exe
drwxrwx---+ 1 SYSTEM SYSTEM 0 Jan 26 11:00 Templates
drwxrwx---+ 1 SYSTEM SYSTEM 0 Jan 26 11:00 Visualizers
-rwxr-x---+ 1 SYSTEM SYSTEM 3116544 Jan 10 13:29 wingdb.chm
-rwxr-x---+ 1 SYSTEM SYSTEM 1363456 Jan 10 13:46 wingdbAdaLanguagePack.dll
-rwxr-x---+ 1 SYSTEM SYSTEM 30208 Jan 10 13:53 wingdbAutomationAPI.dll
-rwxr-x---+ 1 SYSTEM SYSTEM 11030016 Jan 10 13:50 wingdbEngine.dll
-rwxr-x---+ 1 SYSTEM SYSTEM 1495040 Jan 10 13:54 wingdbMakefilePack.dll
-rwxr-x---+ 1 SYSTEM SYSTEM 1845760 Jan 10 13:51 wingdbRemoteTerminalPack.dll
If I go to the start menu and type WinGDB I don't see any executable. However, http://www.wingdb.com/docs/pages/wg_launching.htm instructs me to use the UI I don't know how to launch. How do you launch WinGDB GUI from start menu or command line?

How to execute a unix executable file with Swift

I developing a OS X application with swift. I need to use some library on my application. The library is a Unix executable file.
I can execute the Unix executable file on terminal.
This is example:
pngquant --quality=65-80 test.png
But I need execute the Unix executable file on OS X application. I don't know how to do it.
I think should execute command on OS X application, and find an awesome library to execute the command.
Using swiftline example:
let result = run("ls -all")
print(result.stdout)
Print content:
total 0
drwxr-xr-x 6 DevinShine staff 204 Dec 23 22:18 .
drwxr-xr-x# 3 DevinShine staff 102 Dec 23 22:16 ..
drwxr-xr-x 3 DevinShine staff 102 Dec 23 23:25 Pion.app
drwxr-xr-x 4 DevinShine staff 136 Dec 23 22:18 Pion.swiftmodule
drwxr-xr-x 7 DevinShine staff 238 Dec 23 22:18 Pods.framework
drwxr-xr-x 7 DevinShine staff 238 Dec 23 22:18 Swiftline.framework
I copy Unix executable file to Build Phases.
But I don't know how to move Unix executable file to OS X application and execute it.
Please help me,thx.
I resolved it. The way is easy.
I run my application and execute run("pwd")
let result = run("pwd")
print(result.stdout)
let fullPath = result.stdout + "/Pion.app/Contents/MacOS/pngquant"
print content:
/Users/apple/Library/Developer/Xcode/DerivedData/Pion-ebbvaypzstbbordxhgeutzopihtt/Build/Products/Debug
excute pngquant function:
run(fullPath + " /Users/apple/Documents/test.png")
Update at 2015-12-25
NSBundle.mainBundle().executablePath will give you the path to your .app wrapper, so code is very clear.
run(NSBundle.mainBundle().executablePath + "pngquant /Users/apple/Documents/test.png")

scala.sys.process.Process throws RuntimeException

I'm trying to get diff of two directories recursively and to register them as a github issues.
If the directories has a few files, scala.sys.process.Process works as I expect.
➜ Desktop ls -la
(snip)
drwxr-xr-x# 5 garbagetown staff 170 Sep 19 22:53 2.1.5
drwxr-xr-x# 5 garbagetown staff 170 Sep 19 11:26 2.2.0
(snip)
➜ Desktop ls -la 2.1.5/style
(snip)
-rw-r--r--# 1 garbagetown staff 1206 Sep 19 22:53 book.css
-rw-r--r--# 1 garbagetown staff 278 Sep 19 22:53 external.png
-rw-r--r--# 1 garbagetown staff 175 Sep 19 22:53 header-pattern.png
-rw-r--r--# 1 garbagetown staff 12985 Sep 19 22:53 main.css
➜ Desktop scala
Welcome to Scala version 2.10.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_21).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import scala.sys.process.Process
import scala.sys.process.Process
scala> Process("diff 2.1.5/style 2.2.0/style").!!
res0: String = ""
But the directories has many files and dirs, scala.sys.process.Process throws RuntimeException as below.
➜ Desktop ls -la 2.1.5/manual
(snip)
-rw-r--r--# 1 garbagetown staff 9139 Sep 19 22:53 Highlights.md
-rw-r--r--# 1 garbagetown staff 2737 Sep 19 22:53 Home.md
-rw-r--r--# 1 garbagetown staff 8444 Sep 19 22:53 Migration.md
-rw-r--r--# 1 garbagetown staff 15202 Sep 19 22:53 Modules.md
-rw-r--r--# 1 garbagetown staff 670 Sep 19 22:53 User-Groups-around-the-World.md
-rw-r--r--# 1 garbagetown staff 937 Sep 19 22:53 _Sidebar.md
drwxr-xr-x# 3 garbagetown staff 102 Sep 19 22:53 about
drwxr-xr-x# 7 garbagetown staff 238 Sep 19 22:53 book
drwxr-xr-x# 8 garbagetown staff 272 Sep 19 22:53 detailledTopics
drwxr-xr-x# 9 garbagetown staff 306 Sep 19 22:53 gettingStarted
drwxr-xr-x# 9 garbagetown staff 306 Sep 19 22:53 hacking
drwxr-xr-x# 6 garbagetown staff 204 Sep 19 22:53 javaGuide
drwxr-xr-x# 16 garbagetown staff 544 Sep 19 22:53 sandbox
drwxr-xr-x# 7 garbagetown staff 238 Sep 19 22:53 scalaGuide
➜ Desktop scala
Welcome to Scala version 2.10.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_21).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import scala.sys.process.Process
import scala.sys.process.Process
scala> Process("diff 2.1.5/manual 2.2.0/manual").!!
java.lang.RuntimeException: Nonzero exit value: 1
at scala.sys.package$.error(package.scala:27)
at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.slurp(ProcessBuilderImpl.scala:131)
at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.$bang$bang(ProcessBuilderImpl.scala:101)
at .<init>(<console>:9)
at .<clinit>(<console>)
at .<init>(<console>:7)
at .<clinit>(<console>)
at $print(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:734)
at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:983)
at scala.tools.nsc.interpreter.IMain.loadAndRunReq$1(IMain.scala:573)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:604)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:568)
at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:756)
at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:801)
at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:713)
at scala.tools.nsc.interpreter.ILoop.processLine$1(ILoop.scala:577)
at scala.tools.nsc.interpreter.ILoop.innerLoop$1(ILoop.scala:584)
at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:587)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:878)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:833)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:833)
at scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:135)
at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:833)
at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:83)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:96)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:105)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
How can I solve this problem?
diff has a slightly unconventional way of communicating an exit status. Usually POSIX utils return 0 on success and non-zero on error. Diff returns 0 if there are no differences found, and 1 if differences were found, etc. Process thinks that it was an error in execution and throws an exception. So you need to work around that issue.
One way to do it is to use this method instead (doc):
abstract def lines_!(log: ProcessLogger): Stream[String]
It does not throw on non-zero error status.
For example:
Process("diff 2.1.5/manual 2.2.0/manual").lines_!.foreach(println)

GWT + eclipse, which files are part of my source?

i created a GWT project in eclipse, and it's time to put some code back into source control. i'm not sure at this point which files are generated and can be left out of source control,
a. under war/myapp/gwt/... i see many, many files related to the standard GWT themes.
b. under war/myapp,
-rw-r--r-- 1 10102022 1602597546 1876 Jan 24 16:41 0182DE3CC529E42DA72BBD969A44841E.gwt.rpc
-rw-r--r-- 1 10102022 1602597546 1456 Jan 24 14:09 4F701266A6E52E1E409583EA9AEC39E2.gwt.rpc
-rw-r--r-- 1 10102022 1602597546 1876 Jan 25 08:38 D98FD8FE56B70659E9608109BCF8B3C1.gwt.rpc
-rw-r--r-- 1 10102022 1602597546 43 Dec 16 16:01 clear.cache.gif
drwxr-xr-x 6 10102022 1602597546 204 Jan 25 08:26 gwt
-rw-r--r-- 1 10102022 1602597546 11289 Dec 17 01:33 hosted.html
-rw-r--r-- 1 10102022 1602597546 5232 Jan 25 08:31 photodrop_web_gwt.nocache.js
normally i'd just rely on eclipse build > clean to get rid of the build time artifacts. however, i did that, and i still see WEB-INF/classes full of class files, so i know that clean isn't working.
"war/myapp" is by default GWT's output directory. So as long as you haven't saved any files there manually (you shouldn't), you can delete that directory completely.
As always, make a backup first...
I'm using source control for GWT + GAE, and this ignore file has been working great:
syntax: regexp
^war/myapp$
syntax: regexp
^war/WEB-INF/appengine-generated/datastore-indexes-auto\.xml$
syntax: regexp
^war/WEB-INF/appengine-generated/local_db\.bin