无法使用 TCL 创建文件,该文件通过 PHP 执行
我有一个执行 TCL 脚本的 PHP 脚本。 TCL 脚本创建一个文件,但是当我通过 PHP(从浏览器)执行时,tcl 无法创建文件。
谁能指导我。
//PHP 代码
<?php
$app = 'tclsh84';
$descriptorspec = array(
0 => array("pipe","r"),
1 => array("file","C:/wamp/www/tcl/bin/out.txt","w"),
2 => array("file","C:/wamp/www/tcl/bin/error.txt","w")
) ;
$process = proc_open($app, $descriptorspec, $pipes);
if (is_resource($process))
{
fwrite($pipes[0], 'source c:/wamp/www/tcl/bin/show.tcl'."\n");
fwrite($pipes[0], ' status 124 mithun '."\n");
fclose($pipes[0]);
proc_close($process);
}
?>
//TCL 代码
proc status {id uname} {
set x 1
set outfile [open "report.txt" w]
while {$x < 30} {
set systemTime [clock seconds]
puts $outfile "The time is: [clock format $systemTime -format %H:%M:%S] "
puts $outfile "$id $uname "
set x [expr {$x + 1}]
}
close $outfile
}
未创建文件report.txt。
I have a PHP script that executes a TCL script . The TCL script creates a file , but when I execute through PHP (from browser) , tcl is not able to create a file.
Can anyone guide me .
//PHP code
<?php
$app = 'tclsh84';
$descriptorspec = array(
0 => array("pipe","r"),
1 => array("file","C:/wamp/www/tcl/bin/out.txt","w"),
2 => array("file","C:/wamp/www/tcl/bin/error.txt","w")
) ;
$process = proc_open($app, $descriptorspec, $pipes);
if (is_resource($process))
{
fwrite($pipes[0], 'source c:/wamp/www/tcl/bin/show.tcl'."\n");
fwrite($pipes[0], ' status 124 mithun '."\n");
fclose($pipes[0]);
proc_close($process);
}
?>
//TCL code
proc status {id uname} {
set x 1
set outfile [open "report.txt" w]
while {$x < 30} {
set systemTime [clock seconds]
puts $outfile "The time is: [clock format $systemTime -format %H:%M:%S] "
puts $outfile "$id $uname "
set x [expr {$x + 1}]
}
close $outfile
}
Thef file report.txt is not created .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看您的 TCL 代码,它试图创建一个名为 report.txt 的文件,但您没有指定在目录结构中的哪个位置创建该文件。所以我认为它将尝试在您的网络服务器设置为主目录的目录中创建文件。
更改 TCL 脚本中的文件名,将文件放在您知道可以写入的位置,看看这是否可以解决您的问题。
Looking at your TCL code it is trying to create a file called report.txt but you don't specify where in the directory structure is that it is being created. So I think that it will be trying to create the file in whichever directory you web server has set as it home directory.
Change the file name in the TCL script to put the file somewhere you know it can be written and see if this solves your problem.