I am trying to run a solver (CBC) through the CMD interface.
The following line works and executes properly when I put the input mps file into the same directory as the solver:
CMD>> "solver_path\solver.exe" "input.mps"
However, I want to run the same code as above but give the solver a pathname for the input.txt file. i.e.
CMD>> "solver_path\solver.exe" "C:/.../input.mps"
In the above intance the solver is not able to open the file, I do not understand why this is happening as
CMD>>"C:/.../input.mps"
opens the file so it definitely exists and can be opened.
Any advice would be much appreciated.
Related
I am trying to use a server to do a set of computations for me, and then export the results as a csv to the server to then be transferred to my own computer. I am having trouble exporting files by remotely running a script. I have a .nb file
a = 1;Export[Directory[] <> "/a.csv", a]
Then I transfer the file to the server and with wolframescript run the script:
$ wolframescript -script /location/filename.nb
I expect a file called a.csv to appear in the directory the .nb file is saved in yet it doesn't. I have tried -run and -file and none of them work either. I have also tried a .wl file and it also doesn't work. What am I doing wrong?
As far as I can tell, when using scripts, file operations are more primitive. Functions OpenWrite OpenAppend Write WriteString and Close are key. Options CharacterEncoding FormatType and PageWidth can help with string data / text files. Your example works on the Desktop with:
a = 1; pipeStream=OpenWrite["a.csv",FormatType->OutputForm]; Write[pipeStream,a]; Close[pipeStream]
Save as Wolframscript from Mathematica "name.wls". On Linux, you need to make the file executable see Wolfram Tutorial.
Then at your respective prompt > $ etc
Wolframscript -file name.wls
should run the script file and create a CSV file with the value "1".
This answer reminds that code generated in Mathematica intended for scripting requires Cells to be Initialization cells
I was using Pycharm as my editor to run the scripts since i need to add a task scheduler i had to test the code on the command prompt. Firstly this is the structure of my project.
When i try to run the following line
C:\Users\My_name\AppData\Local\Programs\Python\Python36-32\python.exe "C:\Users\My_name\PycharmProjects\FYP_CB006302\generateSummary.py"
I get this error,
From the knowledge i have i think it is because it doesn't recognize the path.
But when i change the directory to my project folder then give the path to python.exe and type generateSummary.py it works which was done as shown here.
However i highly doubt that this method can be used to task a schedule in Windows. Therefore, any ideas that would to run as shown in the beginning will be helpful.
The problem here is that when you use that line to run a particular script the folder which is causing the error is out of scope.
C:\Users\My_name\AppData\Local\Programs\Python\Python36-32\python.exe "C:\Users\My_name\PycharmProjects\FYP_CB006302\generateSummary.py"
In this case pickle_saves folder is out of scope. You can avoid this by giving a absolute path to that file in line 173. Where the absolute path is something like C:\user\documents\projects\pickle_saves\all_words
I have a symlink named example.avi that points to a real example.avi video file. When a program tries opens the symlink, it really opens the video file. But now I would like execute a command line whenever a program tries to open the symlink file.
Is that possible?
ps: windows
No, there is no built-in way of creating a symlink or other file system object that causes a command to be executed when it is opened by an application.
It should in principle be possible to do this with a file system filter driver. But that's very complicated. I believe there are some third-party tools to simplify this sort of task, but I don't have any experience with them.
While I am clearly ignorant on the subject of symlinks in Windows (see my comments on your question). I just played with it and proved that you could basically do this by symlinking to a wrapper for your avi. I.e. symlink to an exe or a batch file, etc. which does what you want and then opens the avi. Here's a test I ran with txt files and notepad:
Create a file called test.txt with some text. Create a file next to it called test.bat. Here's the batch:
notepad test.txt
When you run the batch, it just opens the txt in notepad.
Then I added a symlink:
mklink test2.txt test.bat
Now, when I type test2.txt in the command prompt, or double click on it, it runs the batch and opens the test.txt file. Obviously, you can use the same basic logic. It doesn't, however, fire the batch off when I open the symlink in Notepad++. It just opens to batch for editing instead.
Of course, maybe you don't want a second file, in which case you need to literally embed your avi in some wrapper. I guess we ned to know more about what you want to do. It sounds like an attempt at malware hidden in a video to me...
I am running a Python script that is meant to launch a .bat file on Windows 7. The batch file runs a sort of Monte Carlo program for 2 minutes. At the end of those 2 minutes the program must update a data file that I will read later in the same Python script, do some data analysis on the output and relaunch the same .bat file if necessary.
I do this process an unlimited amount of time until I get a satisfactory output.
The Python code looks like this
import os
import numpy as np
os.system('myBatch.bat > messages.txt')
while True:
# force flushing
fd = open("output.txt",'a')
fd.flush()
os.fsync(fd.fileno())
fd.close()
# read data
data = np.loadtxt("output.txt")
# some data analysis ...
# testing
if dataSatisfactory:
break
else:
os.system('myBatch.bat > messages.txt')
As you can see I am trying to force flushing the output.txt file that must be written by the program in the batch file. As I have no control over this compiled executable program the output file is not getting updated after the command os.system('myBatch.bat > messages.txt'), but only after I kill the whole python process.
I tried to add the 4 lines after # force flushing, but apparently still not working.
For the sake of clarification, the input of the executable is the output.txt as well as the output, so the executable must over-write the file output.txt.
The file messages.txt is to redirect all the messages of the executable from the stdout to messages.txt.
Any advice or a hint?
NB: The batch file looks like this
.\TheExecutable %output.txt
if your batch file does nothing but calling your monte carlo program, get rid of it and call the program directly from python: os.system("TheExecutable.exe output.txt")
If you can make your program write to standard output instead of a file, you could use subprocess.check_output("TheExecutable.exe") which just returns that standard output. See the documentation of numpy.loadtxt() for functions loading from string instead of a filename.
This way, you completely avoid writing & reading to/from disk.
Short story: need a method to get the write-status of a file on a server (using BASH) from a client (using CMD batch).
Long-time lurker, first-time poster. I did many searches on variations of what I'm looking for and have not yet found enough data.
I am writing a batch file in CMD (because the clients could be any WinOS [XP - up] with unknown packages installed). The batch uses puTTY's "plink" to connect via SSH to the server. Once connected to the server, plink executes a command to write data to a new file.
Once that file is written, I use PSCP to copy the file to the client
So far, so good; I have successfully accomplished all of this.
The creation of that file is instantaneous but the time it takes to write all of the data is unknown / variable. Therefore I need an automated method to determine when the file is complete, to then copy it. Simply using timeout/sleep for XX seconds is not feasible in my circumstances.
The approach I have taken so far (as of yet unsuccessfully) is to repeatedly grab the filesize using "stat -c '%s' filemane" and run that in a loop until grab1 EQU grab2, indicating a complete file. I am finding this difficult because I can't get the output of stat into the CMD batch to process it.
Q1: Is this (stat result going into CMD for loop) the best approach? Maybe there's something existing in BASH?
Q2: if Q1 is true, any ideas on how to get the stat result into the CMD batch as a variable to parse/analyze the data?
Thanks in advance for suggestions and your time.
DCT
Have the command writing the file write it with a temp filename. So if it will be called xyz.txt, have it written with filename tmpxyz.txt.tmp, then the final step will be a rename.
That way you can just check for the presence of the named file.
Usually a good idea to give the file a unique name, probably incorporating the date and time, I find.