Lua, io.input() can't find file - input

I have myfile.txt sitting in the same directory as my lua file, yet when I call io.input("myfile.txt") I get the error bad argument #1 to 'input' (myfile.txt: No such file or directory).
I don't see how this can be going wrong, have I misunderstood Lua's I/O?

You need to fully qualify the path (eg. "/home/username/myfile.txt" on *NIX, "C:\directory\myfile.txt" on Windows). When you don't, the Lua interpreter expects the file to be in the same directory as the interpreter.
Read this question for an easy fix using arg[0] to get the current directory of the script being executed.

Related

Error in running trace32 with command line

I have a .cmm file which helps in debugging of Qcomm chipsets.
This file has a line : cd ../../../../../modem_proc
When I run this same cmm file using T32 GUI, it runs fine and does the work. But when I am trying to run the same file using windows command line using,
C:\T32\bin\windows64>t32mqdsp6.exe -c C:\T32\config.t32 -s D:\path\to\xxx.cmm
Following error is thrown in T32: syntax error in B::cd ../../../../../modem_proc
What am I missing here? I have no hands-on experience with T32 what-so-ever.
The problem probably results from different working directories. Type
PRINT OS.PWD()
in the GUI and add it to the top of the script. I'd suspect they are different.
Don't use working directory relative paths, instead use paths relative to the script, e.g.
CD ~~~~/../../../../modem_proc
The four tilde (~) symbols mean "directory of the currently executed script". There's still a possible issue with this solution when using multiple GUIs and the intercom, but for most use-cases this should be OK.
When starting TRACE32 (up to build 99518) without option "-s", it starts a default script t32.cmm form your TRACE32 installation directory. But t32.cmm is not executed, when "-s" is used.
So probably your t32.cmm is changing your working directory. If so you can fix the issue by adding the line
DO ~~/t32.cmm
to the top of your script xxx.cmm.
See also https://www.lauterbach.com/frames.html?help_autostart.html
The default working path is also set by the TRACE32 configuration file. That is the file passed with "-c". So if your are using a different configuration file than C:\T32\config.t32 when starting your TRACE32 GUI the normal way, then you should use that configuration file also when starting TRACE32 from the command line.
To get the path of the configuration file usually used, start TRACE32, execute command AREAand then command PRINT OS.PCF()
Furthermore dev15 is probably right here https://stackoverflow.com/a/53671657/4727717:
Use paths relative to the PRACTICE script (cmm-file) by starting each path with four tildes.

Can I somehow set the script interpreter in Apache, as opposed to the start of the file?

I am having the following problem:
When I want to run an uncompiled Lua script in Apache, I just add #!/usr/share/lua at the beginning of the file, so far everything works fine.
But if I want to compile it with luac to have it run a bit faster I cannot add any text to the file, as it is compiled binary data (which still needs to be interpreted by the Lua interpreter, and cannot be executed on its own).
Is there a way to tell Apache to always have /usr/share/lua interpret files with the .lua (or .luac to mark them as compiled) extension?
I'm not aware of a way to do this as a CGI script, as the CGI spec basically requires that the shell can figure out how to run a file based on the hashbang at the beginning.
However, you could write a simple CGI handler in Lua that does a loadfile() on the .luac file and then executes it. You can set .luac files to be handled by this script with the following directives in a .htaccess or httpd.conf file:
# Files of a particular file extension
AddHandler my-file-type .xyz
Action my-file-type /cgi-bin/program.cgi
In this example from the docs, program.cgi would be passed the filename requested by the URL so you could parse it and run that file.

unable to open text file

I'm trying to get a program to open a file and read from it. However, I can't seem to get it to open the file. I've read several threads about this and I've seen the suggestion to make sure the file is in the same directory as my executable. I don't know how to check if that's true. The text file is saved in the same file as my program files, if that helps. Can anyone give me some input? Relevant code below. Thanks!
std::ifstream myfile;
myfile.open("../ResInput.txt", ios::in);
if(myfile.is_open()){
getline(myfile, stemp1);...
Your open() call is trying to go up one directory to read the file as it's written right now. If you want the file opened in the same directory as your executable, remove the ../ in your open() call.
This is also assuming your OS accepts a forward slash as a directory separator. It would also be useful to know the error you are getting.

How to specify LINQPAD.config file in lprun

I put my LINQPAD.config in the same folder as LINQPad.exe and it works well for LinqPad GUI.
When I run the same .linq program via lprun.exe. lprun.exe does not use the same LINQPAD.config file as LINQPad.exe but instead it expects a LINQPAD.config file in the same directory as the .linq file which is passed as an argument to lprun.exe.
This is quite inconvenient. Now, I have two options, either copy LINQPAD.config to where my .linq script is or copy my .linq script to where lprun.exe is.
lprun.exe's help doesn't mention anything about specifying a path to LINQPAD.config.
This is a bug and will be fixed for the next LINQPad 5 release (5.0.10). It should pick up the config file from the query folder only if it exists, otherwise it should fall back to the lprun.exe folder.

Using SSIS package to zip all the txt files and move to related folder [duplicate]

I am trying to zip the contents of a Folder in SSIS, there are files and folders in the source folder and I need to zip them all individually. I can get the files to zip fine my problem is the folders.
I have to use 7.zip to create the zipped packages.
Can anyone point me to a good tutorial. I haven't been able to implement any of the samples that I have found.
Thanks
This is how I have configured it.
Its easy to configure but the trick is in constructing the Arguments. Though you see the Arguments as static in the screenshot, its actually coming from a variable and that variable is set in the Arguments expression of Execute Process Task.
I presume you will have this Execute Process task in a For Each File Ennumerator with Traverse SubFolders checked.
Once you have this basic setup in place, all you need to do is work on building the arguments to do the zipping, how you want them. A good place to find all the command line arguments is here.
Finally, the only issue I ran into was not providing a working directory in the command line arguments for 7zip. The package used to run fine on my dev environment but used to fail when running on the server via a SQL job. This was because 7zip didn't have access to the 'Temp' folder on the SQL Server, which it uses by default as the 'working directory'. I got round this problem by specifying the 'working directory as follows at the end of the command line arguments, using the -ws switch:
For e.g:
a -t7z DestinationFile.7z SourceFile -wS:YourTempDirectoryToWhichTheSQLAgentHasRights