I am trying to restart external solver after given elapsed time (3600 sec) but I am not successful, therefore I would like to ask you for help.
Below is my code example. A problem is that first run is in operation and therefore if-else statement which would restart it is not taken in to account.
clc
close all
clear all
tic
! "C:\Program Files\external_solver.exe" -i file1.dat -o file1.out
et = toc
if et > 3600;
! "C:\Program Files\external_solver.exe" -i file1.dat -o file1.out
end
;
Best regards
Michal
Assuming "C:\Program Files\external_solver.exe" -i file1.dat -o file1.out is a valid command, you can append an Ampersand '&' to it for your MATLAB script to continue while the other program executes.
Then, just make MATLAB wait for the amount of time you want, and kill the process in case it is still running. For example:
system('"C:\Program Files\Google\Chrome\Application\chrome.exe" &');
pause(10);
!taskkill -f -im chrome.exe
Related
I’ve several simulations and I start simulation from command line in Windows like:
gatling.bat -s MySimulation1
But how do I pass more simulations so MySimulation1 is executed first and then MySimulation2?
gatling.bat -s MySimulation1 && gatling.bat -s MySimulation2
I'm trying to set up some performance monitors. I also want to do some stuff with the data (csv), including analyzing the data with some PS scripting upon collection segmentation. Here is my PS command to create the logman entry:
logman create counter -n NetLog -f csv -si 00:00:30 `
-cnf 00:01:00 -c "\Network Interface(*)\Bytes Total/sec" -r -v mmddhhmm `
-b 00:00:00 -e 23:59:59 -rc C:\PerfLogs\Admin\NetLogConfig\hello.cmd
Note that the details like segment length and sample interval are only that low for testing purposes. Production will be much different, though undecided as of yet, but I digress. Now, this works great:
logman create counter -n NetLog -f csv -si 00:00:30 `
-cnf 00:01:00 -c "\Network Interface(*)\Bytes Total/sec" -r -v mmddhhmm `
-b 00:00:00 -e 23:59:59
But for some reason, as soon as I add -rc C:\PerfLogs\Admin\NetLogConfig\hello.cmd, the counter stops upon segmentation of the collection period instead of segmenting and continuing. Note that the command to create the counter succeeds, and the counter will start successfully, but the collector set is halted when the file is closed for segmentation. It also does not run the command at all. I have also tried a file type of .bat instead of .cmd, and I have also tried typing a command directly into the -rc parameter (eg -rc echo "Hello World!"). .bat makes no difference, and enetering a command directly will get me a nice error message about it not being an acceptable paramater. Inside the file is a place-holder command that right now goes:
echo "Hello World!"
pause
So how do I get a command to run upon segmentation/file close? I will consider work-arounds, but this seems by far the cleanest solution.
Read newest logman create counter reference:
-[-]rc <task> Run the command specified each time the log is closed.
Note that -rc switch parameter is -rc <task> (in an older Technet document is -rc FileName). So what <task> stands for? Read Data Collector Set Properties and/or run perfmon.exe, see image below:
Task - You can run a Windows Management Instrumentation (WMI) task upon completion
of the Data Collector Set collection by entering the command in the
Run this task when the data collector set stops box.
Refer to WMI task documentation for options.
And finally, from WMI task documentation I have recognized that <task> in -rc <task> should be a name of a scheduled task. Next modification of your attempt might give a proof (a new instance of cmd window flashes every minute and output files are filled as expected):
erase d:\bat\SO\38859079.txt
erase C:\PerfLogs\Admin\NetLog*.csv
logman delete NetLog
logman create counter -n NetLog -f csv -si 00:00:15 -cnf 00:01:00 ^
-rf 00:05:00 -c "\Network Interface(*)\Bytes Total/sec" -r -v mmddhhmm ^
-b 00:00:00 -e 23:59:59 -rc 38859079
logman start NetLog
timeout /T 360 /Nobreak
logman stop NetLog
dir /B /S C:\PerfLogs\Admin\NetLog*.csv
type d:\bat\SO\38859079.txt
Schtasks /Query /FO LIST /V /TN 38859079 | findstr /I /C:"Task To" /C:"Type"
Output:
==> D:\bat\SO\38859079.bat
==> erase d:\bat\SO\38859079.txt
==> erase C:\PerfLogs\Admin\NetLog*.csv
==> logman delete NetLog
The command completed successfully.
==> logman create counter -n NetLog -f csv -si 00:00:15 -cnf 00:01:00 -rf 00:05:00 -c "\
Network Interface(*)\Bytes Total/sec" -r -v mmddhhmm -b 00:00:00 -e 23:59:59 -rc 388590
79
The command completed successfully.
==> logman start NetLog
The command completed successfully.
==> timeout /T 360 /Nobreak
Waiting for 0 seconds, press CTRL+C to quit ...
==> logman stop NetLog
Error:
Data Collector Set is not running.
==> dir /B /S C:\PerfLogs\Admin\NetLog*.csv
C:\PerfLogs\Admin\NetLog_08101250.csv
C:\PerfLogs\Admin\NetLog_08101251.csv
C:\PerfLogs\Admin\NetLog_08101252.csv
C:\PerfLogs\Admin\NetLog_08101253.csv
C:\PerfLogs\Admin\NetLog_08101254.csv
==> type d:\bat\SO\38859079.txt
10.08.2016 12:51:47,99
10.08.2016 12:52:49,04
10.08.2016 12:53:50,06
10.08.2016 12:54:51,07
10.08.2016 12:55:48,00
==> Schtasks /Query /FO LIST /V /TN 38859079 | findstr /I /C:"Task To" /C:"Type"
Task To Run: cmd /c >>d:\bat\SO\38859079.txt echo %date% %time%
Schedule Type: On demand only
==>
Please note than your question has nothing to do with powershell (IMHO wrong tag); in my example is scheduled task to run cmd however it should work for powershell as well.
I've written a shell script to soft-restart HAProxy (reverse proxy). Executing the script from the shell works. But I want a daemon to execute the script. That doesn't work. system() returns 256. I have no clue what that might mean.
#!/bin/sh
# save previous state
mv /home/haproxy/haproxy.cfg /home/haproxy/haproxy.cfg.old
mv /var/run/haproxy.pid /var/run/haproxy.pid.old
cp /tmp/haproxy.cfg.new /home/haproxy/haproxy.cfg
kill -TTOU $(cat /var/run/haproxy.pid.old)
if haproxy -p /var/run/haproxy.pid -f /home/haproxy/haproxy.cfg; then
kill -USR1 $(cat /var/run/haproxy.pid.old)
rm -f /var/run/haproxy.pid.old
exit 1
else
kill -TTIN $(cat /var/run/haproxy.pid.old)
rm -f /var/run/haproxy.pid
mv /var/run/haproxy.pid.old /var/run/haproxy.pid
mv /home/haproxy/haproxy.cfg /home/haproxy/haproxy.cfg.err
mv /home/haproxy/haproxy.cfg.old /home/haproxy/haproxy.cfg
exit 0
fi
HAProxy is executed with user haproxy. My daemon has it's own user too. Both run with sudo.
Any hints?
According to this and that, Perl's system() returns exit values multiplied by 256. So it's actually exiting with 1. It seems this happens in C too.
Unless system returns -1 its return value is of the same format as the status value from the wait family of system calls (man 2 wait). There are macros to help you interpret this status:
man 3 wait
Lists these macros and what they tell you.
A code of 256 probably means that the system command cannot locate the binary to run it. Remember that it may not be calling bash and that it may not have paths setup. Try again with full paths to the binaries!
I have the same problem when call script that contains `kill' command in a daemon.
The daemon must have closed the stdout, stderr...
Use something like system("scrips.sh > /dev/null") should work.
I'm looking for a script to copy and rename one single file in a folder 60 times with backward sequential day in OS X
For example diary.list becomes
20140320_diary.list
20140319_diary.list
20140318_diary.list
20140317_diary.list
20140316_diary.list
....
20140120_diary.list
I know this simple script to copy and rename with previous date to it
cp diary.list $(date -v -1d '+%Y%m%d')_diary.list
But how do I put -1d in a loop so that it repeats 60 times?
Thanks heaps!
for i in `seq 1 60`; do cp -v diary.list $(date -v -`echo $i`d '+%Y%m%d')_diary.list ; done
Omit -v from the cp command to quiet output.
I'm trying to run MATLAB scripts from command-line and am having problems getting MATLAB to return results to stdout.
When running the following command, MATLAB prints the license banner and exits without printing the message.
matlab -nodisplay -nojvm -r "fprintf(1, 'value: %f\n', 2.0); quit;"
*note: I am currently running Version 7.10.0.499 (R2010a) 64-bit (maci64)
As was shown in this related post, you can use the -logfile option to make a copy of all outputs to a file.
matlab -nodisplay -nojvm -logfile out.txt -r "fprintf(1, 'value: %f\n', 2.0); quit;"
On Windows, use the -wait command-line options to block the execution of your script until MATLAB closes.
On Unix, you can use sleep 5s to sleep for 5 seconds, or use the wait command to pause execution until the process finishes:
#!/bin/sh
matlab -nodisplay -logfile out.txt -r "rand(3), quit"
wait $(ps | grep matlab | awk '{print $2}') && cat out.txt