This is a static archive of our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

[Windows 7] Unable to open file in Lua script

0

I am trying to open a text file within my Lua script that is launched from Wireshark. However, it is not clear how to specify the filename as an absolute path or where the file should be stored.

local csv_file = assert(io.open("AP_Batch.csv", "r"))

When this executes I get "nil" back. I tried the following (with the same file copied into C:\temp)

local csv_file = assert(io.open("C:\Temp\AP_Batch.csv", "r"))

Where does Wireshark/Lua expect the current working directory to exist. I've copied the same file into Wireshark's installation folder, my home directory.

Could someone enlighten me what folder I should place the file or how to specify a full Windows style path.

EDIT: I tried C:\\Temp\\AP_Batch.csv, but this failed. The error dialog tells me "No such file of directory" and displays c:\Temp\AP_Batch.csv as what it tried to open

asked 14 May '15, 12:08

carlwain74's gravatar image

carlwain74
1334
accept rate: 0%

edited 14 May '15, 12:14


2 Answers:

0

Some headway on this issue - File turned out to be named AP_Batch.csv.csv in Windows :-(

However, I would still like to know where Lua and Wireshark expect files to exist if no path is specified

answered 14 May '15, 12:55

carlwain74's gravatar image

carlwain74
1334
accept rate: 0%

0

You can refer this lua file io

If no path is specified then io.open API bydefault takes that path where your .lua file is created for example if you have created sample.lua as below and you are trying to read test.lua from that

  1. --Opens a file in read
  2. file = io.open("test.lua", "r")
  3. -- sets the default input file as test.lua
  4. io.input(file)
  5. -- prints the first line of the file
  6. print(io.read())

then test.lua should be in that directory where your sample.lua is created and for the file which is in another directory you can define the path like io.open("D:\lua.txt,"r")

answered 14 May '15, 21:15

ankit's gravatar image

ankit
65232328
accept rate: 25%

ok sample.lua is located in the Wireshark folder. I confirmed that without a path it opens the file in this location.

(15 May '15, 17:12) carlwain74