I need to run a .lua file with another .lua file.
Here is my code:
Program = io.read()
dofile(program)
I type the name of the file that I want to run correctly, but for some reason my compiler says that the file I typed does not exist. (Which it does)
Lua is case sensitive; Program is not program
Otherwise the code should work.
Try putting the full path instead of the relative path. i.e. /home/nick/script.lua
Related
I'm working with C right now. And there's a problem. I don't know how to save a FILE in custom place. When I run *.exe file, it saves them where code is placed. So how to make it save FILEs where I want it to be?(I can input a path)
a FILE is actually a long type that addresses a path on your computer.
Whether you use linux, windows, etc, the common thing about the paths is the idea that there are relative paths or absolute paths.
From what I've understood you probably did use the relative path, and I can guess you didn't specified a path at all, but only the file name.
Notice that a file's name alone is placed relatively to the path of the program you are running.
To fix your problem you might want to give an absolute path (such as "/home/user/" on linux or "C:\Users\user" on windows [pay attention for the escaping backslash]).
You can do it by something like this:
FILE *output = fopen("/home/user/output.txt", "w");
(where "w" means writing permissions to the file at the given path).
Hope this answers your question.
I wrote my program in C which includes calling a bash script and another external program from it (all of them located in the same directory as my C program). I set the path of the executing files strict so like:
char *path_for_the_script = "location/of/script.sh";
and compile my program.c without any special arguments..
Now I wonder how can I manage that this path gets set by the program, so that someone else could use it from his computer without changing the paths manually?
Load the path from a environment variable (also add a fallback or failure path if the variable is not set) and have your program being launched through a wrapper script, which the user can adjust.
Example
in yourprogram.c
char const * const path_for_the_script = gentenv("YOURPROGRAM_SCRIPT_PATH");
the programlauncher.sh
#!/bin/sh
export YOURPROGRAM_SCRIPT_PATH="..."
exec yourprogram $#
Instead of setting the path in your code, create a text file in the same directory and fetch the path information from the txt file. Thus anyone can modify the text file with required path and execute the program, with out any code modification.
create a file in same directory as source.txt
vi source.txt
location/of/script.sh
In your program, use file open operation and access the file contents and assign to path_for_the_script char buffer. This method works only when all the users share the same computer.
I am making a program that optimises a PC and I have made some exe's I need a bat file that can run them even if they had an extension like "abc". I cant have them with the exe extention because if they were executed not in order it could be fatal
EDIT: does any one know how I could do the same but with a reg file with a "abc" extention as well. Thanks.
you dont need to change the registry to run an file with different extension.YOu just need to add the extension to %PATHEXT% :
set "pathext=%pathext%;.exe1"
call sample.exe1
to make a an .abc file to act as .reg try this:
assoc .abc=regfile
I need to read file in my program so while providing path I want to give relative paths because all files to be opened will be in some folder within current folder.
I tried this:
FILE *f=fopen("./abc/p.txt","r")
abc is folder withing current folder, but fopen returns NULL. How to do this thing?
This comes from either one of those:
. or ./abc/ is not readable or traversable
./abc/p.txt is not readable
./abc/p.txt does not exist
./abc/p.txt is a broken link
Look at errno to know what's the real problem.
this will run:
FILE *f=fopen("...\\abc\\p.txt","r");
I've been adding a plugin to an existing project, and the thing is tied together with a perl script. I'm trying to add my C program into the perl script to make an output file, but the output is garbage or missing.
My executable is called Interpolate and when it's in the same folder as the perl script it's working just fine
./Interpolate inv.tracking_log
Is how the command is run. It should produce an intermediate filecalled tmp.log, and a final file called out.txt. When I run it in the directory it does just fine, both files are as they should be.
So then I added a system call into the perl script (I barely (if that) know perl):
print("./Interpolate $inVideoFile"); //prints like the command (just a test)
my $interCall = system("./Interpolate $inVideoFile");
When running it from within the perl script, the tmp.log file is mostly garbage, and out.txt is missing entirely. I do realize out is most likely missing because it has a dependency on the tmp.log file. Is there a perl 'gotchya' that I'm missing somewhere?
system("./Interpolate $inVideoFile");
should be
system("./Interpolate", $inVideoFile);
If you still have a problem after fixing that, $inVideoFile doesn't contain what it should, or there's a bug in your C program. (What is the return value of the system call?)