Hi!
I need to copy a text file from the function code, which I then analyze line by line. Because the source file is changing too fast. In many programming languages, it is possible to call MSDOS commands (file copying, renaming, etc.). There are no such full-time operators in PL. Does anyone have any idea how this can be implemented? So far the best I've come up with is to create a file — a flag (pl can do it), when it appears, an external program (running in an infinitely loop) creates a copy of the required file. I understand that this is a crooked decision, and it is not clear how to check that the copy was successfully made
Copy file [SOLVED]
-
- Posts: 275
- Joined: 22 Apr 2014
- Has thanked: 70 times
- Been thanked: 72 times
Re: Copy file
Take a look at the lua thread. viewtopic.php?t=49242
You need to use os.execute and there are two ways to do this depending on how you want it to work. If you call a batch file then control will be returned to Multicharts as soon as the batch file executes. If you execute a command or external application directly that calculates something then control will be returned to Multicharts when that finishes executing.
Code looks like this which should get you going.
You need to use os.execute and there are two ways to do this depending on how you want it to work. If you call a batch file then control will be returned to Multicharts as soon as the batch file executes. If you execute a command or external application directly that calculates something then control will be returned to Multicharts when that finishes executing.
Code looks like this which should get you going.
Code: Select all
If Barstatus(1) = 2 and LastBarOnChart then
begin
LuaState = Lua.New();
Lua.Exec(LuaState, "f = os.execute([[ command goes here ]])");
//Lua.Exec(LuaState, "f = os.execute([[ path + batchfile.bat ]])");
Lua.Close(LuaState);
end;
Re: Copy file
Thank You very much! I really do not know Lua, but I hope to understand.Take a look at the lua thread. ....
-
- Posts: 275
- Joined: 22 Apr 2014
- Has thanked: 70 times
- Been thanked: 72 times
Re: Copy file
Hi Shaman, if you use the code example above and just add your copy command within the brackets after the os.execute it should work.
regards,
Alex
regards,
Alex
Re: Copy file
Hi Shaman, if you use the code example above and just add your copy command within the brackets after the os.execute it should work.
Yes thank you! I'm doing this right now. But it looks like I had a war with escaping quotes ("" and /) between PowerLanguage and LUA. I can not win yet.
Lua error: [string "command"]:1: invalid escape sequence near '"d:\m'
Lua error: attempt to call a nil value
LuaCode = f = os.execute("d:\mytest.bat")
I'm already confused in all variants of the type:
Lua.Exec(LuaState, "f = os.execute("d:\mytest.bat")");
and
temp_str = DoubleQuote + "d:" + "\" + "mytest.bat" + DoubleQuote ;
Lua.Exec(LuaState, "f = os.execute(" + temp_str + ")");
and
Lua.Exec(LuaState, "f = os.execute("d:\mytest.bat")"); --- it doesn't compile PL
Please help me to correctly write a call to the file
D:\mytest.bat
Re: Copy file
If place the bat-file in the MС directory (where the DLL is), then it works. because you do not need to specify the path.
temp_str = DoubleQuote + "mytest.bat" + DoubleQuote ;
Lua.Exec(LuaState, "f = os.execute(" + temp_str + ")");
But with the path still does not work
temp_str = DoubleQuote + "d:" + "\\" + "mytest.bat" + DoubleQuote ;
temp_str = DoubleQuote + "mytest.bat" + DoubleQuote ;
Lua.Exec(LuaState, "f = os.execute(" + temp_str + ")");
But with the path still does not work
temp_str = DoubleQuote + "d:" + "\\" + "mytest.bat" + DoubleQuote ;
-
- Posts: 275
- Joined: 22 Apr 2014
- Has thanked: 70 times
- Been thanked: 72 times
Re: Copy file
Here is a cut and paste from my code which has a path for the java.jar that I am calling. See if that format helps.
Code: Select all
LuaState = Lua.New();
Lua.Exec(LuaState, "f = os.execute([[C:\\ProgramData\\Oracle\\Java\\javapath\\java.exe -jar
C:\\Users\\flemi\\IdeaProjects\\HMM65XXX\\out\\artifacts\\HMM65XXX_jar\\HMM65XXX.jar]])");
Lua.Close(LuaState);
Re: Copy file [SOLVED]
Thank you for help!Here is a cut and paste from my code which has a path for the java.jar that I am calling. See if that format helps.
Re: Copy file
Hi!
Unfortunately I could not solve the problem - I just need to copy the file inside the signal.
I tried a lot of options. lua himself works for me.
If you copy files by invoking the copy command MS DOS, windows constantly blink on the screen, which are intercepted by the cursor, etc. - It certainly does not suit me.
Attempting to apply the impressive hidden program launch utility in Windows is not working, the MC generates a critical execution error.
As a result, I came to the conclusion that it is best to use the function "copyfile" built into Lua. But I can not run it. I tried all the options for placing square brackets and apostrophes, but it does not work - which is very strange (because other teams work well). I was already exhausted. Help please, who can!
// lua WORK!
Lua.Exec(LuaState, "f = io.open([[D:\qq.txt]], [[w]])");
Lua.Exec(LuaState, "f:write([[Lua says hello333!]])");
Lua.Exec(LuaState, "f:close()");
// WORK! but on the screen constantly appearing and disappearing cmd-windows blink
Lua.Exec(LuaState, "f = os.execute([[D:\\mytest.bat]])"); Lua.Close(LuaState);
// WORK! but on the screen constantly appearing and disappearing cmd-windows blink
Lua.Exec(LuaState, "f = os.execute('cp " + DoubleQuote + "temp.csv" + DoubleQuote + " " + DoubleQuote + "log.csv" + DoubleQuote + "')"); Lua.Close(LuaState);
// External utility does not work - MC gives a critical error. but without the MC, the utility works great!
Lua.Exec(LuaState, "f = os.execute([[C:\\HiddenStart\\hstart64.exe /NOCONSOLE /UAC /NONELEVATED " + DoubleQuote + "C:\\HiddenStart\\mytest.bat" + DoubleQuote + "]])"); Lua.Close(LuaState);
// Don't work! Lua error: [string "command"]:1: attempt to call a nil value (field 'copyfile') - LuaCode = f = os.copyfile([[D:\MyFile.csv]],[[D:\MyFile2.csv]])
Lua.Exec(LuaState, "f = os.copyfile([[D:\MyFile.csv]],[[D:\MyFile2.csv]])"); Lua.Close(LuaState);
// Don't work! Lua error: [string "command"]:1: attempt to call a nil value (field 'copyfile') - LuaCode = f = os.copyfile('"D:\\MyFile.csv","D:\\MyFile2.csv"')
Lua.Exec(LuaState, "f = os.copyfile('" + DoubleQuote + "D:\\MyFile.csv" + DoubleQuote + "," + DoubleQuote + "D:\\MyFile2.csv" + DoubleQuote + "')"); Lua.Close(LuaState);
Unfortunately I could not solve the problem - I just need to copy the file inside the signal.
I tried a lot of options. lua himself works for me.
If you copy files by invoking the copy command MS DOS, windows constantly blink on the screen, which are intercepted by the cursor, etc. - It certainly does not suit me.
Attempting to apply the impressive hidden program launch utility in Windows is not working, the MC generates a critical execution error.
As a result, I came to the conclusion that it is best to use the function "copyfile" built into Lua. But I can not run it. I tried all the options for placing square brackets and apostrophes, but it does not work - which is very strange (because other teams work well). I was already exhausted. Help please, who can!
// lua WORK!
Lua.Exec(LuaState, "f = io.open([[D:\qq.txt]], [[w]])");
Lua.Exec(LuaState, "f:write([[Lua says hello333!]])");
Lua.Exec(LuaState, "f:close()");
// WORK! but on the screen constantly appearing and disappearing cmd-windows blink
Lua.Exec(LuaState, "f = os.execute([[D:\\mytest.bat]])"); Lua.Close(LuaState);
// WORK! but on the screen constantly appearing and disappearing cmd-windows blink
Lua.Exec(LuaState, "f = os.execute('cp " + DoubleQuote + "temp.csv" + DoubleQuote + " " + DoubleQuote + "log.csv" + DoubleQuote + "')"); Lua.Close(LuaState);
// External utility does not work - MC gives a critical error. but without the MC, the utility works great!
Lua.Exec(LuaState, "f = os.execute([[C:\\HiddenStart\\hstart64.exe /NOCONSOLE /UAC /NONELEVATED " + DoubleQuote + "C:\\HiddenStart\\mytest.bat" + DoubleQuote + "]])"); Lua.Close(LuaState);
// Don't work! Lua error: [string "command"]:1: attempt to call a nil value (field 'copyfile') - LuaCode = f = os.copyfile([[D:\MyFile.csv]],[[D:\MyFile2.csv]])
Lua.Exec(LuaState, "f = os.copyfile([[D:\MyFile.csv]],[[D:\MyFile2.csv]])"); Lua.Close(LuaState);
// Don't work! Lua error: [string "command"]:1: attempt to call a nil value (field 'copyfile') - LuaCode = f = os.copyfile('"D:\\MyFile.csv","D:\\MyFile2.csv"')
Lua.Exec(LuaState, "f = os.copyfile('" + DoubleQuote + "D:\\MyFile.csv" + DoubleQuote + "," + DoubleQuote + "D:\\MyFile2.csv" + DoubleQuote + "')"); Lua.Close(LuaState);
-
- Posts: 275
- Joined: 22 Apr 2014
- Has thanked: 70 times
- Been thanked: 72 times
Re: Copy file
Try using Robocopy instead of copy. https://sumtips.com/how-to/robocopy-com ... -switches/. Place the Lua call within an Barstatus(0) = 2 condition so that it does not run every tick.
Try embedding Robocopy into a batch file and call that. I am calling a java application that runs without problems every hour at bar close so there must be a way.
I will take a look to see if I can come up with a working solution and get back to you.
regards,
Alex
Try embedding Robocopy into a batch file and call that. I am calling a java application that runs without problems every hour at bar close so there must be a way.
I will take a look to see if I can come up with a working solution and get back to you.
regards,
Alex
Re: Copy file
Thanks for the help! Unfortunately, robocopy also blinks windows. Since I need to copy the file about 2 times per second, I am looking for a solution without the appearance of any windows. I need a recount inside the bar, and I use RecalcLastBarAfter(0.5)Try using Robocopy instead of copy. https://sumtips.com/how-to/robocopy-com ... -switches/. Place the Lua call within an Barstatus(0) = 2 condition so that it does not run every tick.
Alex
Re: Copy file
Thanks for the help! Unfortunately, robocopy also blinks windows. Since I need to copy the file about 2 times per second, I am looking for a solution without the appearance of any windows. I need a recount inside the bar, and I use RecalcLastBarAfter(0.5)Try using Robocopy instead of copy. https://sumtips.com/how-to/robocopy-com ... -switches/. Place the Lua call within an Barstatus(0) = 2 condition so that it does not run every tick.
Alex
-
- Posts: 275
- Joined: 22 Apr 2014
- Has thanked: 70 times
- Been thanked: 72 times
Re: Copy file
Hi Shaman, I am sorry that you are running into trouble. You are doing these copies faster than I expected!
I think with that kind of frequency, you should think about using something like Sharedvar server and forget about copying files. It is easy to setup and very convenient.
regards,
Alex
I think with that kind of frequency, you should think about using something like Sharedvar server and forget about copying files. It is easy to setup and very convenient.
regards,
Alex
Re: Copy file
Thanks for the help! And if I would have copied 1 time per minute, how would I write the line correctly?.... You are doing these copies faster than I expected!...
Lua.Exec(LuaState, "f = os.copyfile([D:\MyFile.csv],[D:\MyFile2.csv])"); Lua.Close(LuaState);
I have a critical application error at any frequency.
Best regarts
Alex
- Attachments
-
- ошибка-3107.png
- (16.11 KiB) Downloaded 202 times