在我的automation.php
控制器内,我有以下功能:
public function deploy_test() {
echo json_encode(system("python --version"));
}
Run Code Online (Sandbox Code Playgroud)
当用户想要部署测试时,通过单击test
网页中的按钮,他将能够完成这样的任务.但是,当我单击test
按钮时,我的输出是:
""
Run Code Online (Sandbox Code Playgroud)
同时,当我用命令执行相同的功能时:
public function deploy_test() {
echo json_encode(system("ls -l"));
}
Run Code Online (Sandbox Code Playgroud)
我越来越:
total 32
drwxr-xr-x. 15 philippe philippe 4096 Mar 4 16:48 application
drwxrwxr-x. 2 philippe philippe 4096 Mar 4 17:28 css
-rw-r--r--. 1 philippe philippe 6357 Jan 30 11:53 index.php
drwxrwxr-x. 2 philippe philippe 4096 Feb 27 15:38 js
-rw-r--r--. 1 philippe philippe 2496 Jan 30 11:53 license.txt
drwxr-xr-x. 8 philippe philippe 4096 Jan …
Run Code Online (Sandbox Code Playgroud) 我是个新手node.js
.我正在尝试使用node.js实现一个浏览器性能工具,所以我有以下代码:
for(var j=0; j < 14; j++) {
// Create a new instance of HttpWatch in Firefox
var control = new ActiveXObject('HttpWatch.Controller');
var plugin = control.Firefox.New();
// Start Recording HTTP traffic
plugin.Log.EnableFilter(false);
// Clear Cache and cookier before each test
plugin.ClearCache();
plugin.ClearAllCookies();
plugin.ClearSessionCookies();
plugin.Record();
// Goto to the URL and wait for the page to be loaded
plugin.GotoURL(url);
control.Wait(plugin, -1);
// Stop recording HTTP
plugin.Stop();
if ( plugin.Log.Pages.Count != 0 )
{
// Display summary statistics for page …
Run Code Online (Sandbox Code Playgroud) 我正在编写一个函数,它将创建一个zip文件,该文件将用于其他功能.下面是我的函数代码:
public void createZip(){
try{
String outfile = this.filename + ".zip";
//input file
FileInputStream input = new FileInputStream(this.filename);
//output file
ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(outfile));
//name the file inside the zip file
System.out.println(this.filename);
zip.putNextEntry(new ZipEntry(this.filename));
byte[] buffer = new byte[this.BUFFER];
int len;
//copy the file to the zip
while((len= input.read(buffer)) > 0){
System.out.println(len);
zip.write(buffer, 0, len);
}
zip.closeEntry();
zip.flush();
input.close();
zip.close();
this.filename += ".zip";
}
catch(IOException e){
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
我试过调试,但我找不到这个问题的根源.该函数运行没有任何进一步的问题,但zip文件产生它是一个空的.
我想动态地创建一个带有一些参数的链接到一个页面,其中将使用这些值:
<td><a href="${createLink(controller:'display', action="viewer", params: ['file' : '${stream.file}', 'media' : '${stream.media}'])}">${fieldValue(bean: streamInstance, field: "media")}</a></td>
Run Code Online (Sandbox Code Playgroud)
在我的viewer.gsp
我想在显示视频流中的链接使用这些值:
<source src="path/to/my/videodir/${media}" type='video/mp4'></source>
Run Code Online (Sandbox Code Playgroud)
但到目前为止我没有取得多大成功:-(.有人可以帮助我吗?
我写了一个程序,需要在Linux,Windows和Solaris上进行测试.前两个很容易,但Solaris非常麻烦.我在Solaris机器上没有g ++我正在运行那些测试,所以我坚持不懈cc
.所以,我第一次尝试:
cc -g -o transfer transfer.cpp -lcurl
Run Code Online (Sandbox Code Playgroud)
输出是:
ld: fatal: file transfer.cpp : unknown file type
ld: fatal: no output written to transfer
Run Code Online (Sandbox Code Playgroud)
如果有人知道任何其他原生C++
编译器Solaris
,请告诉我,我会试一试.我去了Oracle Solaris网站,他们说他们支持.cpp
文件cc
.有人可以帮帮我吗?谢谢
我用来MySQLdb
操作MySQL
数据库,并且我有以下例程,将一些数据注入名为的表中urls
:
def insert_urls(dbconn, filenames):
root = "<path>/"
link = "http://<url>/"
for f in filenames:
filename = root + f + ".html"
local_url = link + f + ".html"
print(filename, local_url)
sql = """
INSERT INTO urls(url, filename) VALUES('%s', '%s');
""" % (local_url, filename)
print(sql)
dbconn.execute_query(sql)
Run Code Online (Sandbox Code Playgroud)
该表的声明urls
可以在这里找到:
def create_urls_table():
sql = """
CREATE TABLE IF NOT EXISTS urls (
id INT NOT NULL AUTO_INCREMENT,
url BLOB NOT NULL,
filename BLOB NOT NULL,
PRIMARY …
Run Code Online (Sandbox Code Playgroud) 我正在尝试确定某些文件的数据一致性.但是,MD5的变化不同.当我执行时md5sum
,哈希是相等的:
import hashlib
import os
import sys
def hash_file_content(path):
try:
if not os.path.exists(path):
raise IOError, "File does not exist"
encode = hashlib.md5(path).hexdigest()
return encode
except Exception, e:
print e
def main():
hash1 = hash_file_content("./downloads/sample_file_1")
hash2 = hash_file_content("./samples/sample_file_1")
print hash1, hash2
if __name__ == "__main__":
main()
Run Code Online (Sandbox Code Playgroud)
输出意外地不同:
baed6a40f91ee5c44488ecd9a2c6589e 490052e9b1d3994827f4c7859dc127f0
Run Code Online (Sandbox Code Playgroud)
现在md5sum
:
md5sum ./samples/sample_file_1
9655c36a5fdf546f142ffc8b1b9b0d93 ./samples/sample_file_1
md5sum ./downloads/sample_file_1
9655c36a5fdf546f142ffc8b1b9b0d93 ./downloads/sample_file_1
Run Code Online (Sandbox Code Playgroud)
为什么会发生这种情况,我该如何解决这个问题呢?
我有以下 python 片段:
from datetime import datetime
timestamp = '05/Jan/2015:17:47:59:000-0800'
datetime_object = datetime.strptime(timestamp, '%d/%m/%y:%H:%M:%S:%f-%Z')
print datetime_object
Run Code Online (Sandbox Code Playgroud)
但是,当我执行代码时,出现以下错误:
ValueError: time data '05/Jan/2015:17:47:59:000-0800' does not match format '%d/%m/%y:%H:%M:%S:%f-%Z'
Run Code Online (Sandbox Code Playgroud)
我的匹配表达式有什么问题?
我正在尝试用grails/groovy编写文件和视频的上传器.因此,每次用户填写新表单时,控制器都会上传文件并将文件名和其他字段一起保存到数据库中.所以,这是保存程序:
def save = {
def streamInstance = new Stream(params)
if(request){
MultipartHttpServletRequest mpr = (MultipartHttpServletRequest)request;
CommonsMultipartFile uploadedFile = (CommonsMultipartFile)mpr.getFile("myFile");
if(!uploadedFile.empty){
println "helloworld"
println "Class: ${uploadedFile.class}"
println "Name: ${uploadedFile.name}"
println "OriginalFileName: ${uploadedFile.originalFilename}"
println "Size: ${uploadedFile.size}"
println "ContentType: ${uploadedFile.contentType}"
/*
//def webRootDir = servletContext.getRealPath("/")
//def userDir = new File(webRootDir, "/files/${session.user.login}")
//userDir.mkdirs()
uploadedFile.transferTo(new File("/Users/philipperibeiro/ctv/ctv/web-app/files"))
streamInstance.file = uploadedFile.originalFilename
*/
}
else{
flash.message = "file cannot be empty"
}
}
if(!streamInstance.hasErrors() && streamInstance.save(flush : true)){
flash.message = "${message(code: 'default.created.message', args : [message(code: 'stream.label', default:'Stream'), streamInstance.id])}" …
Run Code Online (Sandbox Code Playgroud) 我正在编写一个对.log
文件执行一些操作的函数:程序/logs/ansible.log
在继续之前检查是否存在。如果/logs/ansible.log
不存在,它应该继续创建文件/目录结构(两者都不存在)。
try:
if not os.path.exists("/logs/ansible.log"):
# create the /logs/ansible.log file
finally:
# do something
Run Code Online (Sandbox Code Playgroud)
我知道我可以用 来创建ansible.log
文件open('ansible.log', 'w')
并用 来创建目录os.makedirs('/logs/')
,但是我怎么能简单地'/logs/ansible.log'
一次创建呢?
*** 假设程序被执行为 root
python ×5
grails ×2
c++ ×1
codeigniter ×1
groovy ×1
hash ×1
java ×1
javascript ×1
md5 ×1
mysql ×1
mysql-python ×1
node.js ×1
php ×1
solaris ×1
zip ×1