Re: TaintedString.parseInt problem

2016-08-08 Thread OderWat
Here another `hexdump()`: import strutils proc hexDump*(s: string | cstring, cols: int = 16, offs: int = 2): string = result = newStringOfCap(s.len * 3 - 1 + (s.len div cols + 1) * (offs + 2)) var newLine = true for idx, c in s: if idx > 0:

Re: TaintedString.parseInt problem

2016-08-07 Thread dom96
> @Flyx For such a case something like a hexdump echo of strings would be nice. > I was looking for such proc some months ago -- is there something available? You can use `repr` to get a better idea of what characters are contained a string.

Re: TaintedString.parseInt problem

2016-08-07 Thread flyx
@luntik2012: From documentation of `execProcess`: > WARNING: this function uses poEvalCommand by default for backward > compatibility. This means that it executes the command within a shell, which is probably responsible for the trailing newline. @Stefan_Salewski: Well, it's easy enough to

Re: TaintedString.parseInt problem

2016-08-07 Thread luntik2012
@flyx Thank you, it works. And it's interesting, because after executing "that_cmd >> file" file doesn't contain trailing whitespaces O_o

Re: TaintedString.parseInt problem

2016-08-07 Thread Stefan_Salewski
@luntik2012 Sorry, saw my mistake short time period after sending the post... @Flyx For such a case something like a hexdump echo of strings would be nice. I was looking for such proc some months ago -- is there something available?

Re: TaintedString.parseInt problem

2016-08-07 Thread Stefan_Salewski
Why not use echo to see the content of the string you pass to parseInt? Note: for bash command expr / indicates integer division. For Nim / is floating point division, you may use div for integer division, or you may round the floating point result. So may guess is that you pass a floating

Re: TaintedString.parseInt problem

2016-08-07 Thread luntik2012
execProcess return type is TaintedString, so I don't think it's float(bash performs division and returns string)

Re: TaintedString.parseInt problem

2016-08-07 Thread flyx
The problem is that the result of `execProcess` contains trailing whitespace (a newline in this case). Try: return execProcess(command & "" & filepath & ) / 1000""").strip.parseInt

TaintedString.parseInt problem

2016-08-07 Thread luntik2012
proc getLen*(filepath: string): int = const command = """expr $(mediainfo --Inform="Audio;%Duration%" """ return execProcess(command & """ & filepath & ) / 1000""").parseInt I'm executing this command in bash and getting result "347": expr $(mediainfo