Running a Pydev Program with Task Scheduler - scheduled-tasks

I am trying to schedule a daily run of a pydev eclipse program that prints the output to a text file. My file is called automated.py, and my command is
/c automated.py > logall.txt
It starts in C:\Users\cmai\eclipse-workspace\test, which is the location of the file. However, when I run the command, the text file it produces is blank. Thank you for your help!

The fact that it was created on PyDev is probably not relevant to executing it in Python.
Shouldn't your command be something as:
python automated.py > logall.txt?

Related

How to source environment file in python?

I am trying to automate an application restarts with Python which is currently implemented with shell scripts. Before running the restart commands, we need to source a .sh environment file which is done in the shell script with
. ./opt///**.sh. I am using paramiko and exec_command to run the restart command which throws the error that libraries are missing. So I have tried several ways to source this environment file in the python program but have not been successful.
Things I have tried:
stdin1,stdout1,stderr1 = ssh_client1.exec_command(". ./opt///**.sh")
stdin1,stdout1,stderr1 = ssh_client1.exec_command("source /opt///**.sh")
subprocess.call("/opt///**.sh", shell=True)
os.system(". /opt///**.sh")
I picked the below from stack overflow if I remember correctly
enter code herecommand = shlex.split("bash -c 'source /opt///**.sh'")
enter code hereproc = subprocess.Popen(command, stdout = subprocess.PIPE)
enter code herefor line in proc.stdout:
enter code here(key, _, value) = line.partition("=")
enter code hereos.environ[key] = value
enter code hereproc.communicate()
I still get the same error missing libraries which I am supposed to get when I do not source the environment file when I run the application restart commands using exec_command("/opt///start")
Any help is really appreciated.
Thanks.
#Martin Prikryl: Execute multiple commands in Paramiko so that commands are affected by their predecessors
I love you man!! I am writing a py script to remote ssh with paramiko that sources a local environment file before running application restart commands. I was breaking my head over this for over 2 weeks, until I read this post. It works like a charm. Thank you!!
Solution:
Each exec_command multiple times is executed in its own "shell". So the previous commands have no effect on an environment of the following commands.
Use && to combine the commands. In this way, the previous command, which in my case is the environment file, has an effect on the following command.
stdin3,stdout3,stderr3 = ssh_client1.exec_command(". /opt///env.sh && STOP")

Execute jar and display text in jenkins console log

I have abc.jar file to deploy and run in remote machine.
I have transferred the file using jenkins, now what I have done is, call a a.bat batch file on remote machine using psexec in Execute Windows Batch Command.
a.bat executes the abc.jar
When the jar begins execution, the command prompt texts are stored in a file.
using java -jar abc.jar >> a.log 2>&1
Now what I want is to display the a.log contents in the jenkins console when the jar file is being executed
(the file is continuously being written and I want to show it in jenkins console as it is being written)
I have tried to do it using parallel processing by calling start twice, one for calling batch file, another using type for displaying.
But when I use start I get Process leaked file descriptor .
Is there any other way I can achieve this. Be it calling powershell or scheduled task in jenkins.
You need to look for tee equivalents in windows , there are few like GNU utilities for Win32, however if you have cygwin you can still use tee which will easy the prcoess.
Now the wuestion arises how to run my jar file on cygwin from jenkins ?
you can still use execute windows[batch] shell. and add cygwin installation path to the PATH variable and start using linux command like a BOSS.
or you can use powershell tee in built command from batch.

how to run a cmd file from matlab

I am trying to run a cmd file from MATLAB but unable to execute it. Can anybody see nay problem in the below code?
this is what I have inside my cmd file:
echo on
>test.log 2>&1 (
C:/testProj/Make/makeit.cmd param1
)
And this is the MATLAB code:
Out = 'C:/testProj/test.cmd';
system(Out);
But this actually does not run the cmd file.
Well for somereason it would not run if i would give the complete path of the cmd in bat file. so I had a cd command to change the directory and then run. now it runs fine, Thanks all appreciate your help!
What about using eval, like this:
eval(['!test.cmd']);
I have succesfully used this to run .bat files (and this output of the .bat script showed in my matlab command line). I also found this dos command, but I am not sure if it works allright:
You can just type the following strings to get things down:
!(c:/testProj/test.cmd)
This is actually no different from
system('c:/testProj/test.cmd')
I think you should check if the path is wrong. As to your code in the cmd file, that's beyond my ability to help.

"time" command in Cygwin works, but not in NetBean

I can do this in Cygwin, adding time Command
USER#USER_PC ~
$ time ./HelloWorld
shows smthing like
Hello World!!!
real 0m0.270s
user 0m0.270s
sys 0m0.270s
I've deployed an similar C/C++ Project #NetBean7.2 #Win 7.
It shows error message at Run time, Only when I add time Command ,like:
time "${OUTPUT_PATH}"
,at the Text Field of Projcet_file-> R_Click -> Properties -> Run -> Run_Command:
,and default value ${OUTPUT_PATH} only.
Error message is
C:\ProjectFolder\time does not exist or is not an executable
,seems that NetBean consider time as an excutable
Any better ways to solve it??
full command to bash needs to be in quotes if calling from cmd shell
bash -c "time ls"
time is a builtin command of bash. On my cygwin installation the proper command is:
c:\cygwin\bin\bash -c time
You have to adjust the path to bash.

Calling a command line program

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