run的参数问题 (对变量加"") Topic is solved

遇到了问题?请先进行搜索(中文和英文),然后在此提问

Moderators: tmplinshi, arcticir

wei9133
Posts: 11
Joined: 08 Sep 2014, 13:01

run的参数问题 (对变量加"")  Topic is solved

Post by wei9133 » 24 Sep 2023, 03:33

版本︰1.1.37.1
事情是这样的,弄了一个改menu的脚本,下面这个大部分可以正常运行
但碰到脚本的位置带空格的就会出错,看起來空格造成分割的
若将run后面的参数改成绝对位置 run, 程式位置 脚本位置
例:
run, E:\工具\小工具\文書處理\Notepad++ 8.5.7\notepad++.exe "F:\GoldWave 6.7.7 Portable\新增 test.ahk"
这个就可以运作
但这就碰到问题了,要怎把A_ScriptFullPath变成"F:\GoldWave 6.7.7 Portable\新增 test.ahk",然后还能被当成变量

path := % "A_ScriptFullPath" ;出来的结果是A_ScriptFullPath
path := % """ . A_ScriptFullPath . """ ;出来的结果是 " . A_ScriptFullPath . "

需要的路径我转换不出来,结果就变成脚本有空格的话就不运作
还是有什么更好的写法呢?

Code: Select all

menu, tray, NoStandard ;先刪除原始的menu
menu, tray, add ; 分隔符
menu, tray, add, 以notepad++開啟 ;新增 "以notepad++開啟"的菜單,下方必須有相應的sub
menu, tray, add, 開啟腳本所在位置
menu, tray,Color, CCCCFF , Single ;變更菜單顏色
menu, tray, Standard ;追加原始菜單,讓新增的菜單顯示在最上而不是最下
return
/*
下面以notepad++開啟腳本,run,後為絕對路徑,%A_ScriptFullPath%則是當前使用中腳本的路徑
若notepad++換新版的需將絕對路徑做修正。
*/

以notepad++開啟:
run, E:\工具\小工具\文書處理\Notepad++ 8.5.7\notepad++.exe %A_ScriptFullPath%
return

開啟腳本所在位置:
run, % A_ScriptDir
return
[\code]

[img]https://imgur.com/a/e9Rwu8D[/img]

garry
Posts: 3777
Joined: 22 Dec 2013, 12:50

Re: run的参数问题 (对变量加"")

Post by garry » 24 Sep 2023, 10:40

OK , use > E:\工具\小工具\文書處理\Notepad++ 8.5.7\notepad++.exe "%A_ScriptFullPath%"

Code: Select all

;-------- saved at 星期日 九月 2023-09-24  15:26 UTC --------------
;- run的参数问题 (对变量加"") 
;- https://www.autohotkey.com/boards/viewtopic.php?f=27&t=121744

menu, tray, NoStandard ;先刪除原始的menu
menu, tray, add ; 分隔符
menu, tray, add, 以notepad++開啟 ;新增 "以notepad++開啟"的菜單,下方必須有相應的sub
menu, tray, add, 開啟腳本所在位置
menu, tray,Color, CCCCFF , Single ;變更菜單顏色
menu, tray, Standard ;追加原始菜單,讓新增的菜單顯示在最上而不是最下
return
以notepad++開啟:
run,E:\工具\小工具\文書處理\Notepad++ 8.5.7\notepad++.exe "%A_ScriptFullPath%"  ;- filename =  "C:\Users\garry\Desktop\SLIDESHOW RANDOM\run的参数问题_(对变量加)_ NEW 20230924172627.ahk"
return
開啟腳本所在位置:
run, % A_ScriptDir
return
esc::exitapp

Code: Select all

transform,s,chr,34
path1 := A_ScriptFullPath
path2 := s . A_ScriptFullPath . s 
msgbox,Path1=%path1%`nPath2=%path2%
Image

wei9133
Posts: 11
Joined: 08 Sep 2014, 13:01

Re: run的参数问题 (对变量加"")

Post by wei9133 » 25 Sep 2023, 17:39

可正常使用了,非常感谢
其中transform的指令可替换成s := Chr(34)

transform,s,chr,34
OR
s := Chr(34)
以上皆可運作

附上ASCII的表
ASCII Table
Dec = Decimal Value
Char = Character

'5' has the int value 53
if we write '5'-'0' it evaluates to 53-48, or the int 5
if we write char c = 'B'+32; then c stores 'b'


Dec Char
---------

Code: Select all

  0  NUL (null)
  1  SOH (start of heading)
  2  STX (start of text)
  3  ETX (end of text)
  4  EOT (end of transmission)
  5  ENQ (enquiry)
  6  ACK (acknowledge)
  7  BEL (bell)
  8  BS  (backspace)
  9  TAB (horizontal tab)
 10  LF  (NL line feed, new line)
 11  VT  (vertical tab)
 12  FF  (NP form feed, new page)
 13  CR  (carriage return)
 14  SO  (shift out)
 15  SI  (shift in)
 16  DLE (data link escape)
 17  DC1 (device control 1)
 18  DC2 (device control 2)
 19  DC3 (device control 3)
 20  DC4 (device control 4)
 21  NAK (negative acknowledge)
 22  SYN (synchronous idle)
 23  ETB (end of trans. block)
 24  CAN (cancel)
 25  EM  (end of medium)
 26  SUB (substitute)
 27  ESC (escape)
 28  FS  (file separator)
 29  GS  (group separator)
 30  RS  (record separator)
 31  US  (unit separator)
 32  SPACE
 33  !
 34  "
 35  #
 36  $
 37  %
 38  &
 39  '
 40  (
 41  )
 42  *
 43  +
 44  ,
 45  -
 46  .
 47  /
 48  0
 49  1
 50  2
 51  3
 52  4
 53  5
 54  6
 55  7
 56  8
 57  9
 58  :
 59  ;
 60  <
 61  =
 62  >
 63  ?
 64  @
 65  A
 66  B
 67  C
 68  D
 69  E
 70  F
 71  G
 72  H
 73  I
 74  J
 75  K
 76  L
 77  M
 78  N
 79  O
 80  P
 81  Q
 82  R
 83  S
 84  T
 85  U
 86  V
 87  W
 88  X
 89  Y
 90  Z
 91  [
 92  \
 93  ]
 94  ^
 95  _
 96  `
 97  a
 98  b
 99  c
100  d
101  e
102  f
103  g
104  h
105  i
106  j
107  k
108  l
109  m
110  n
111  o
112  p
113  q
114  r
115  s
116  t
117  u
118  v
119  w
120  x
121  y
122  z
123  {
124  |
125  }
126  ~
127  DEL

garry
Posts: 3777
Joined: 22 Dec 2013, 12:50

Re: run的参数问题 (对变量加"")

Post by garry » 26 Sep 2023, 03:06

@wei9133 非常感谢

Code: Select all

s:=Chr(34)
path1 := A_ScriptFullPath
path2 := s . A_ScriptFullPath . s 
msgbox,Path1=%path1%`nPath2=%path2%
exitapp

Post Reply

Return to “请求帮助”